One note: the return on some companies may be higher and others lower, the issue is that the risk for money in companies is higher.
Very simplistic example: the US government can offer you a flat 5%, a company investment offers 10% half the time, 0% the other half.
One is a sure thing, one is a gamble. The more the 'gamble' the more risk and that is a driving factor in investments. People are willing to take huge risks if the payoff is very large (Look at Michael Burry and the big short)
Of course this is a gross oversimplification: earnings can grow, stocks can pay dividends, companies can go bankrupt, and companies have to pay their own bondholders as well as stockholders. But hopefully it shows that a tradeoff between stocks and bonds does exist.
Now, bonds are guaranteeing a 5%+ return, so a non-profitable business is much less attractive as a proposition.