Also, Congress can mandate what NASA must spend its money on. The recent SLS launch was years late and billions over budget, but Congress passed it so that former Space Shuttle contractors would still get money. Many in NASA would have liked to cancel the rocket and spend the money for other projects but Congress forced them to build it.
That is the constant struggle within NASA. There is the pure science side, and the manned space side.
The manned side is necessary, for the ‘60s saying, “No Buck Rogers, no bucks” still holds sway with many in Congress.
Without the hope of man physically reaching beyond the Earth, space research funding would have dried up even further than it had.
Also, regarding “Congress can mandate what NASA must spend its money on”: that is why I called their spending “capricious”.
SLS is a kludge based on ancient technology. Many in NASA and its contractors would have liked to start over and do it right. For example, back in the early 2000s they looked at the specs and design for the Saturn V "F-1" engine ... then started over and designed an engine to EXCEED those specs using modern materials and fabrication techniques. Congress would not allow it.