NASA did all the hard work for previous decades. SpaceX benefited from that knowledge and experience.
As much fun as people have repeating this little factoid, the problem is that NASA stopped innovating and started becoming nothing more than a pork funnel to certain districts. Had NASA continued to innovate, or at least continued to remain relevant, the door wouldn't have been open for SpaceX to step through. True reusability, rather than the Shuttle's "months of rebuilding" routine, and not throwing away boosters and launch stages are innovation simply because NASA, through government mandated handcuffs, were unable to work towards those goals in a realistic fashion. In fact, when SpaceX started, the mentality that it couldn't be done was so entrenched that there were a lot of folks publicly saying they would fail outright in reusability on the scale they proposed. And here we are today with the Falcons making the reusability of the Shuttle program seem like a joke.
Please note: I'm not in any way a fan of Musk the man, but SpaceX has provided innovation in an industry that desperately needed it. If NASA were capable of doing what SpaceX has done, they were prevented from doing so by congressional mandate.
EVERYONE who creates progress does so by standing on the shoulders of those who came before. This self-evident statement seems redundantly silly to have to repeat every time some dares commit the offense of being impressed with the progress SpaceX has actually managed to create.