If NASA was a profitable enterprise, it wouldn’t require external funding, and Lockheed and co would be doing that research themselves to keep that profit for themselves.
NASA isn’t like CNSA or Roscosmos in that they don’t make their own rockets. It exists first and foremost to funnel money to aerospace contractors by either directly contracting with them or providing R&D in cases where cost/risk is greater than expected profit.
A similar relationship exists with publicly funded universities selling patents to pharma.
Just because a river flows south doesn’t mean you couldn’t find an eddy in the currents that flows north for a few seconds.
But the water still has nowhere to flow but south. If the cost was less than expected return, these companies would do this research internally. Even if for just one moment, one tiny aspect of the program did make a profit, it wouldn’t change the nature of the system.