It’s a perversion of the truth which is that officers or directors of a corporation have a fiduciary duty to the shareholders to act in the interests of those shareholders and not to eg enrich themselves.
But that doesn’t mean the duty is to maximize next quarter’s profit. Long term sustainability is also broadly in the interests of shareholders. The duty likewise does not require one to throw ethics and morals out the window.
This is why shareholders elect the board of directors, in theory.
In theory, companies can act in any way they choose as long as the owners approve (there's some supreme court ruling on that), and executives have a high degree of latitude in how they interpret "for profit" (basically there has to be a vaguely defensible rationale) but failing that, they must act to the benefit of the company. And the easiest way to do that without a risk of being sued is to make the line go up.
(And even ignoring that, the executives often have personal motivations that have the same effect, and may just point at the "legal" angle as ass covering)