Companies are under no obligation to profit. They are completely free to fail and go bankrupt. They would like to profit and not fail, but they are under no legal obligation to do so.
In the USA you can sue publicly traded companies if you feel that management has been derelict and hope for the best in the court system, but in general you are quite right. My previous job was working for a US subsidiary of a European telco. I don't like to name who I worked for because I don't want to give them free publicity as I still, years later, have some grudges against them and how they treated their US based employees. Anyway, we competed in a market segment as a minnow against much bigger fish like AT&T. Our bigger competitors could offer pretty much the same stuff we did but cheaper because they had economies of scale in North America that we couldn't match that enabled them to have a lower price structure. Desperate to get business, our European bosses somehow got a major American company with offices all around the world as a customer. I don't want to name the company or what we did for them, but you would be absolutely appalled to know what we did for them, the fact that they needed it done at all, and the fact that they were too stupid to just do it themselves. I'll just vaguely say that we fixed a major email issue for them. We sold this service at a huge loss just to be able to get their business because management decided that if we could tell prospective clients that we had company X as a customer, we could get more business. It didn't work. In fact, it not only didn't work, our crazy North American sales team took it as a green light to literally sell everything they could at any price, even if at a loss, just to get business. Our CEO had to send out a company wide email around the world to every employee saying that we could no longer sell services to customers at a loss. That's how bad it got. Another point is that Amazon lost truckloads of money for years after it started and I remember investment writers seriously asking in the 1990s if the company would ever turn a profit. Sometimes you have to run at a loss to get established and hopefully you have the money available to do that.