To justify government research, the results need to be compared to the alternative. Had NASA scientists not been working for the government, they would have been working for private companies engaged doing useful work. The Soviet Union had similar resources to the US, yet their research budget was spent wholly by government, whereas a large portion of the US research during that time was directed by private companies. If you want to restrict the comparison just to the US, ask yourself what would the massive wealth that was dedicated to NASA had produced had it been directed by private interests? What would NASA engineers have produced had they been employed by in Y-Combinator-style startups? (or even big private companies like Google, Apple, Facebook, Amazon, etc.)