SpaceX is a privately held company and therefore has less financial pressure on it then say, Tesla.
Elon founded the company with his own money but since then there have been many investors; individuals, venture capital firms investment funds, etc.
SpaceX does of course generate a lot of revenue from launch contracts. See SpaceX - Wikipedia Quote: “As of March 2018, SpaceX had over 100 launches on its manifest representing about $12 billion in contract revenue.”
Of course that’s not enough to fund FH/Starship development and production of large numbers of spacecraft or enable the company to reach its goal of establishing a self-sustaining colony on Mars. That will take a lot more money.
Over 70 launches, at, maybe $10m net profit per launch. That’s $700m. The NASA contracts have some big margins. They’ve had well over $2B in private investment.
So, yes, it does make money, but then it undoubtedly invests more than it makes for future projects, just like any fast growing startup. Musk has no money, he invested it all in SpaceX and Tesla already about ten years ago. Oh, he’s “worth” billions, but that’s the value of his ownership in Tesla and SpaceX, and he hasn’t sold any shares of those companies so he has no cash. Most of his extravagant expenses (like a private jet) are corporate expenses, so paid directly by Tesla or SpaceX, and the rest of his personal expenses are easily paid via modest (for a CEO) salaries.
There's a difference between generating revenue and turning a profit. SpaceX doesn't really do the latter, they basically survive (and of course, grow) on private funding, development contacts from the government, revenue from their launch services, and no doubt some favorable tax deductions form claiming a lot of IRAD. There is no possible way SpaceX would survive as a public company, at least right now.
I don't know exactly how SpaceX contracts are structured with the government, but typically government contracts in the space industry are fixed margin, somewhere around 10-12%. The exercise is in justifying the cost, and that's where clever accounting can help, but that's usually with follow-on activity where you basically use already-justified numbers as a basis. An FFP can of course bring higher margins, but they’re not going to be mega.
Musk has no money, he invested it all in SpaceX and Tesla already about ten years ago. Oh, he’s “worth” billions, but that’s the value of his ownership in Tesla and SpaceX, and he hasn’t sold any shares of those companies so he has no cash.