Software is tricky
Software developed entirely by government employees is usually not copyrighted. Software developed by a NASA contractor might well be covered by copyright. Typically, what happens is that NASA gets a "limited non-exclusive government use" license. That is, NASA can use it, other government entities can use it, but the general public cannot. This comes about because NASA is saving money - they're paying to solve a NASA problem, not the general public's problem, and companies are free to charge more for a "free distribution no license" scenario.
It's also complicated by things like the Bayh-Dole Act, which says that educational institutions doing work for the government retain the intellectual property rights.
In general, though, one can get non-commercial use licenses fairly easily.
That all said, the whole area is one where there's a lot of inconsistency - and it gets muddled when you're talking about software that is the combination of multiple sources, each with different licenses. The "easy way" is to not redistribute such software - no redistribution, no worries about whether GPL applies, etc.