It's certainly enormously expensive. But... most things are. Waste is an extremely relative thing, even when it seems obvious. Basic research discovers things that normal iterative research never does. And space tech discovers things through scale, overcoming myopic outlooks in the way an Access database doesn't illuminate how distributed multi-region databases scale.
For example, what do you do with all that captured coal dust and slag we get from power plants scrubbing their exhaust? We could throw it away, but it turns out there are industries that would love to pay to take that garbage away and use it as a filler their process. We could have stuck with the argument that scrubbing is too expensive to be worth the trouble, and that it would never be practical. Or we can just do the engineering and try it out, and maybe new markets open up. Or not; at least we got some cleaner air.
There's a lot of risk, like any venture. Possibly garbage is just garbage. Possibly there's no reasonable return on investment. Possibly entire industrial supply chains shift to a new technology for the marginal improvement. Possibly a new process for extracting carbon nanotubes is discovered. Or we simply find a cool new color of black for our sports cars.
Maybe the data collected from the moon tells us that it's really just some fairly boring rock not worth our time. Maybe we learn that crystals grown in space can have a perfect crystal structure useful in manufacturing stable q-bits. Maybe we find an asteroid made of platinum and all energy markets brace for a massive tech change, or parhaps it's made of iron and we move on. Or... not; at least we got some pictures for the philosophers and the next generation is inspired to try harder.
The wins from basic research come from the unknown unknowns, and as such can be disruptive like an outside-context-problem [0]. Or are trivial duds; you can't tell at the start, but you can hope. Transistors and lasers are pretty useful! They alone are likely worth all the money we've ever thrown (or ever will) at basic research. Likewise satellites also changed the world, allowing us to do things that likely make all the money we spend on space easily worth it.
<insert some comment about Y Combinator startups maybe becoming billion dollar enterprises... but many fail.>
[0] https://en.wikipedia.org/wiki/Excession#Outside_Context_Prob...