If you read the wikipedia page for SpaceX (which is as neutral as you are likely to get) you see that in the first 10 years of operation, SpaceX spend $1 billion, of which $200M were private investments (Musk $100M) and $400M came from NASA via progress payments on launch contracts, so yes SpaceX was primarily funded through government contracts. It doesn't really matter if they made a profit or not, the growth of SpaceX is largely build on government spending.
I'm not sure how you think investment works. He is not donating his money to SpaceX and it disappears. If the government contracts increase the value of SpaceX it is increasing his investment.
> It doesn't really matter if they made a profit or not, the growth of SpaceX is largely build on government spending.
Well, yes, they're a real company providing real services and getting paid in exchange.
Anyway, whether the contracts are private or government is off-topic (if it was, I'd point out that the government is getting a really good deal here, which is a very rare case in large-scale government spending). The point is, all that money isn't being funneled to line Musk's pockets, it's being reinvested straight into "let's go to Mars" R&D program.
In ways we are already seeing tangible benefits:
supply missions and passenger missions to the ISS,
Commercial and military satellite launches,
Starlink.
Future benefits this tech would potentially support:
asteroid mining, colonising other planets.
The other company I reference have not made a commercially viable rocket that will get you into orbit.