A lot of innovation was initially funded by the government especially in Silicon Valley. That said, Spacex is still legally a private company.
Many a time, when companies engage in capital intensive business endeavours they need someone to provide some incentive or even build the initial technology. NASA does this here much like DARPA did with the Internet's initial infrastructure.