If companies were already profitable why would they go public?
Same reason they take private investments or loans: To grow faster than would be possible without that.
Clearly to hedge the risk of $580 Billion in long term commitments by seeking funds from public markets.
public investment can be magnitudes larger than your profit, allowing growth that would otherwise not be possible
It used to be the norm for companies to become profitable, then IPO, moreso for megacorps.
If I am remembering my history correctly, the first company to go public with a multi-billion dollar valuation while being unprofitable was Netscape, which kicked off the dotcom bubble.
To let early investors exit? Most private funds like that have a horizon of 10 years, so they want to sell their investments at some point.