*for their research papers. It sound strange that the other public-funded research and development department gave them away for free.
In general, any Intellectual Property that is developed by the US government is considered in the public domain, because the US taxpayer has already paid for it, and so charging royalties is essentially the equivalent of charging them twice. There is a sort of appealing civic logic to this, although it is not at all one that all nations share (the UK vigorously asserts Crown Copyright and will happily charge you for its IP). Even in the US it is not universal, because a contractor to the US government can indeed generate IP in the form of copyrights and patents, and whether they are allowed to retain title to it (or whether that title is assigned to the US government) depends on the specific contract under which they are engaged in their work. During World War II, for example, there were two types of contracts that the Office of Scientific Research and Development used with regards to contractors. Well-established contractors doing work at already-existing locations (like DuPont working at its Wilmington plant) would be allowed to keep title to any patents generated so long as they granted the US government royalty-free access to it. But they could commercialize it and sell it later to the private sector if it turned out to be profitable. The argument for this arrangement is that a) it was the norm in these fields, and b) these contractors were supposedly doing their government work for less money than they'd normally make, and so this was their extended compensation.
But for any situation in which the facility the work was being done in was being constructed for the purpose of the WWII research (like Los Alamos or Hanford or the MIT Rad Lab), and for any work that was judged to be sufficiently novel as to not be part of a pre-existing industry (like fission or radar or other "new" techs), the OSRD contracts were title-taking, in that any IP developed had to be assigned to the War Department, and that meant, essentially, giving them to the public domain and killing the possibility of monopolizing them. The head of the OSRD, Vannevar Bush, pushed hard for this arrangement — he really believed that taxpayer money should not result in the creation of private property, in a sentiment that seems earnest and perhaps old-fashioned today. He was quite aware of what he was doing. As he reflected in his memoirs, "I suppose that in the process [of this contract arrangement], I personally destroyed more property in the form of patents than any other man living."
You are right to note that public universities do no such things as this; this is exclusively a federal government issue. Public universities are state-funded organizations and have entirely different charters and arrangements, and many of them are notoriously title-taking. If you are employed even as an undergraduate production assistant at the University of California (as I was, many years ago), the first thing you must do is sign a joint Loyalty Oath (!!) and Patent Policy. The Loyalty Oath (a story unto itself) says you will fight to protect the Constitution (!), and the Patent Policy says that if you invent anything while in your job, its title will be assigned to the University of California, who is under no obligation to pay you a penny for it. (Or at least, that was the gist of it back in 1999.) Many public universities like the UC make a huge portion of their revenue from patent royalties and are incredibly litigious about them. (This is an aside, but during WWII there was a tricky situation in which the title for a major nuclear patent — that governing the extraction of plutonium from spent fuel — was disputed between the scientists who did the work, the UC where they were employed at the time of doing the work, and the federal government who wanted control of all atomic-bomb related patents. The federal government won, in the end.)
Now even the federal government situation has changed over the years. The Bayh-Dole Act of 1980 explicitly tried to increase the ease and rate at which federal contractors were able to keep their IP, and to increase the amount of "technology transfer" from universities into the private sector. There were some hold-out agencies, like the Department of Energy, who seemed unwilling to change their habits, though, and routinely retained title on IP developed. All of which is just to say, this is not something that went into place once and was forever unchanged; it is something that has ebbed and flowed over time, and no doubt has complexities today that I am not aware of. Looking around, there are now agencies that explicitly advertise government-owned patents that can be commercialized (for fees), which seems like quite a post Bayh-Dole approach. (The stated goal of Bayh-Dole was to incentivize technological development and enhance innovation; it was believed, perhaps rightly and perhaps not, that adding more profit-motive would incentivize invention.)
But it should be clear, I think, that the issue was not so much the US government saying, "oh, we invented this, and are magnanimously giving this to the private sector free," but more of a sense that, especially in the years between, say, 1942 and 1980, there was a sense that things developed with taxpayer money were in a sense owned by the taxpayers, so passing on additional costs related to them was unethical.
Most of my knowledge of this comes from the OSRD/AEC/DOE cases, and esp. the World War II debates and choices over contracts. I have published [an article about atomic bomb-related patenting in some depth](https://alexwellerstein.com/publications/wellerstein_patentingthebomb(isis).pdf) that goes into this history, especially Bush's efforts, and is the source of the quote above.