Think of it like security backed bonds, if you bundle a lot of dud businesses into a single business that is doing ok then as an aggregate it looks fine. So bundling Twitter and xAi into SpaceX covers up that. This is why I suspect they will eventually merge Tesla into SpaceX as it is on the decline now.
The problem is that with the current cash on hand and large loans coming due, they only have a 6 month runway. Thus the IPO to get other peoples money to hopefully fund themselves until solvent.
All IPO's are essentially that, people invest in your business, the business uses their money to achieve more, and if it all works out then future profits can eventually be paid back to investors.