You are correct. Nobody has ever been able to point to a law requiring companies to maximize profits for shareholders at all costs.
In fact, there are thousands and thousands of companies that exist with a primary purpose of doing things other than making money for their shareholders.
Any "legal" obligation to "maximize shareholder value" started out as a way to excuse the greed of other people, but falls flat upon even cursory examination.