There are (very limited) lawful structures that try to make this happen, but much more is down to culture. In many (most?) countries it is considered shameful if a company prioritises shareholder value above everything else. I honestly believe the US is an exception in this regard. Unfortunately US culture is taking over.
- And now to go on a complete tangent: In the second part of "The Three Body Problem" trilogy, The Dark Forest, institutions are described that have both an operational officer and a political officer. The navy has an Admiral that decides the strategy, and a political officer that makes sure the Navy does the right thing. The same is then applied to companies. - I wonder if this is a model to apply to a capitalist society: Where you have a CEO doing their regular thing, but also a political officer making sure society is not disadvantaged. Hard to pull off without falling into totalitarianism I guess.