This is actually built on a false premise. NASA can, and does, charge for patent usage. See this page for what it takes to get a NASA patent license. Note this:
including higher royalties
Or this one:
NASA will collect a standard net royalty fee
This shows the NASA process for managing patents. They actually will pay the inventor a portion of the proceeds, next to the agency that released it, and finally, if it makes enough money, a portion to the treasury.
Note that NASA regularly issues patents royalty free for use in NASA missions. It seems they have also freed patents for uses that will ultimately save them money, such as giving some to SpaceX and Blue Origins.
NASA estimates that it's patents have provided a total revenue of \$5.1 billion to the licensees of such patents over a decade. That is only a very small part of NASA's budget, and furthermore, they probably only receive a small percentage of that. If they receive 10% (Which is high for a licensee of a patent), that still is only \$500 million over 10 years, not nearly enough to pay for NASA. It seems very unlikely that the 5% threshold has been reached to pay patents back to the Treasury, meaning that NASA is barely able to profit from any of its patents, excluding the R&D costs. Including those, it is likely losing money from patents. That is okay, as the mission is to spur innovation, not make a profit.