If they are publicly traded and their principal business is not risk, then they are required to be by law.
I'm fairly certain there is no such law. What publicly-traded businesses are required to do is to do what they say they'll do in their articles of incorporation and their prospectus. For most, these documents state that their focus is to generate a responsible return on investment (language varies, but that's what it boils down to). However, it is perfectly acceptable for them to include other goals, and even to prioritize those goals over making money.
Were SpaceX to go public, they could specify that their primary goal is to get to Mars, for example, rather than to make money. That would probably lower their valuation, but there would be nothing at all illegal about it.