Many fields of research will only pay off after a long time. When this time horizon exceeds a certain time, say 30 or more years, the private market begins to experience distortions because investors don't want to put money into a project that will only pay off after they are dead. A huge return in 60 years is useless if you're dead.
You can argue all you want that government tends towards inefficiency, and I'll even agree with you. However, when the only two choices are government research and zero research, well, I think you can see the picture. Attitudes like this are the reason projects such as ITER, CERN, and others are chronically under funded. Private markets are becoming more and more relevant in space, and eventually NASA will have to change its mission parameters because private companies will become so good at rocketry and satellite maintenance. Until then, it absolutely is a legitimate government function to subsidize research into scientific frontiers that the free-market will not due to timeline and payoff distortions.
TLDR: If you're going to complain about wasted taxpayer dollars, at least pick a field that records investment losses. The contributions of NASA and similar veins of research to our society have been of immeasurable economic, social, and military benefit.