I was curious about why NASA publishes all the results/data from its operations. Does the USA have a law that mandates it or is it a voluntary contribution to the world?
It's required to by the legislation that created it, the National Aeronautics and Space Act of 1958.
FUNCTIONS OF THE ADMINISTRATION
Sec. 203. (a) The Administration, in order to carry out the purpose of this Act, shall--
(1) plan, direct, and conduct aeronautical and space activities;
(2) arrange for participation by the scientific community in planning scientific measurements and observations to be made through use of aeronautical and space vehicles, and conduct or arrange for the conduct of such measurements and observations; and
(3) provide for the widest practicable and appropriate dissemination of information concerning its activities and the results thereof.
I drive by it every day... We do it for the benefit of all:
Really though, the government has a vested interest in making sure we (the United States) remain a technology leader in the world because it's good for the economy. Private industry is usually too risk-averse to undertake basic research with no current applications even though the payoff can sometimes be huge.
Because they're scientists, and publishing your results is what scientists do. There's a reason why the final step of basically every research methodology used in academia is "publish your results" (and I'm only saying "basically every" because I'm not an expert on the field of research methodologies, so while it's possible that there's one obscure one out there that doesn't, it doesn't seem likely to me).
Also because they're legally obligated to do so by the rules of their government funding, as pointed out in Organic Marble's answer.
NASA is not a stand-alone thing. It is the civilian part of the space industry, and partially, the military industry of the USA. They work together.
For example: they publish the photos, what the Hubble made. This is very useful for the whole humanity. But the same (or very similar) technologies are used in spy satellites, too. Only the watch not the sky, but the Earth. Of course nothing is known about their capabilities and results. Not even the engineering details of the Hubble are public - only its results.
Most countries have some law enforcing the access of the tax-payers to the results of their tax. This can be avoided on national security reasons, but it needs to have a reason. The law of the USA probably doesn't enforce to publish the results for the whole world, but it is practically impossible to narrow, for example, the availability of the Hubble photos to the USA citizens. It has also much better PR to openly publish it.