The entity is the civil court system, and while there is no law written "no company can work in a way that doesn't maximize profit", upon taking investment, it's typical that companies, the fiduciary, come under the expectation that they'll be working for the sake of their beneficiary's interests. In public companies, this interest is clear-cut. Investors want dividends and to see the value of the company increase. This is typically done through maximizing of profits.
So while it's not explicit that they must forever maximize profits, companies can be successfully sued for not doing so.
Learn more: