Benefiting from open-sourced research that was publicly funded (https://www.inverse.com/article/15272-nasa-releases-rocket-a...) probably also helped a little :))
Also don't forget that the US federal government is an important SpaceX client.
And yes, Nasa (and the DOD) are probably the most important customers of SpaceX... So? Its not like SpaceX are getting free money there. They are providing a service to the government, and getting paid for it - And providing that service at a lower cost than the government would bear if they did it themselves, and a lower cost than their competitors (I'm looking at Boeing - They are getting paid 60% more than SpaceX per seat for commercial crew flights to the ISS)
Also look into the Raptor engine SpaceX have developed. Its a key plank for their future mars ambitions. Its the most advanced rocket engine ever developed and SpaceX funded its development themselves.
I agree Elon is backed by incredibly smart and possibly overworked people and that contributes to his own reputation undeservedly, but he’s driven a company that has made more space progress than most of humanity. Let’s give him some credit on that front and let him spill his own cash on the crazy ideas at least. “Completely overrated” is a bit too far.