I don’t think there’s any legislated law that states that, but some courts treat it as a basic principle (especially in the state of Delaware). What I’ve usually seen as an early example of this is Dodge v. Ford Motor Co. from 1919. Henry Ford had amassed a surplus of more than $60 million (equally to more than $1.1 billion today) and wanted to reinvest that money in expanding the business with new factories while continuing to raise wages and cut prices on the Model T. As part of this he wanted to cease special shareholder dividends he had been playing out of the surplus. Brothers John Francis Dodge and Horace Elgin Dodge owned 10% of Ford and sued to keep the dividend payments coming.
The court ruled that Ford had to pay out a dividend of more than $19 million (more than $360 million today) to the minority shareholders. In the ruling, in a non-binding section, the judge wrote:
A business corporation is organized and carried on primarily for the profit of the stockholders. The powers of the directors are to be employed for that end. The discretion of directors is to be exercised in the choice of men to attain that end and does not extend to a change in the end itself, to the reduction of profits or to the nondistribution of profits among stockholders in order to devote them to other purposes.
Ford was accused of trying to turn the business into a charity. Behind the scenes, though, one of his main motivations for not wanting to pay the dividend was suspicion that the Dodge brothers were using the dividends from his successful business to setup a rival car company to compete against him, which was exactly what they were doing.
It seems the interpretation of the ruling is controversial, even as to whether “maximize shareholder value” is actually enforceable or what the judge meant. I continue to think that the more investors a company has, the less the company will be able to focus on what’s best for the company, customers, and employees in the long run.