(Another united-states answer)
There really is no legal difference between the two cases you mention. The general principle in both cases is the same: an employee can spend her work time writing papers, and publishing them in paywalled journals, if and only if this is allowed by her employer and any applicable contracts. Beyond that, it's really a business decision on the part of each employer whether this is something that they want their employees to do.
It may well be that many universities and research institutes choose to say yes, and many private companies choose to say no, but there are exceptions, and neither choice is either forbidden or required by law.
As user6726 points out, the basis for this is the principle of work for hire: that if an employee produces a copyrightable work in the course of their job, the copyright by default belongs to the employer. But the employer can, if they so choose, turn around and give the copyright back to the employee. Many universities have internal policies that make this automatic (example); but again, the law doesn't require this. Conversely, a private employer would be free to have such a policy if they wanted. And once the copyright belongs to the employee, she is free to transfer it to a paywalled journal if she wants, or to anyone else whom she wishes.
You write:
Of course you can't do that [publish in paywalled journals, etc] in situation 1 [if you work for a private company].
Sure you can, if the company agrees you can. As an example with which I happen to be familiar, here is a recent research paper published in a paywalled commercial journal, one of whose authors (Yuval Peres) is an employee of a private company (Microsoft Research). The article's title page says the copyright belongs to the publisher (Springer-Verlag GmbH), so Microsoft must have agreed to transfer it. Now perhaps they had some sort of internal process to approve this, and to verify that the paper didn't contain any proprietary information, but that's entirely up to Microsoft.
Research grants add a wrinkle. They are usually structured as a contract between the funding agency and the researcher's employer. This contract would normally include a provision saying what should happen to the copyrights of any works created in the course of the funded research. As one example, most US government funding for research in the physical sciences comes through the National Science Foundation, and they have the following policy:
732.2 The following copyrightable material clause will be used in every funding agreement awarded by NSF that relates to scientific or engineering research unless a special copyrightable material clause has been negotiated. [...]
(b) Except as otherwise specified in the grant or by this paragraph, the grantee may own or permit others to own copyright in all subject writings. The grantee agrees that if it or anyone else does own copyright in a subject writing, the Federal government will have a non-exclusive, nontransferable, irrevocable, royalty-free license to exercise or have exercised for or on behalf of the U.S. throughout the world all the exclusive rights provided by copyright. Such license, however, will not include the right to sell copies or photorecords of the copyrighted works to the public.
This says, in short, that the US government doesn't want the copyright and the grantee (i.e. the researcher's employer) can keep it. (The government does retain a license which permits them to use the work but not to sell it.) If the employer has an internal policy like I described above, they may transfer it on to the researcher herself, who may in turn transfer it to a commercial publisher or whoever else. But again, if the NSF were to change their policy, they could start insisting, for newly awarded grants, that all copyrights must be turned over to the government, or released into the public domain, or they could place other restrictions on what could be done with the work. This might, of course, discourage some researchers from applying for NSF grants (though probably not).
(It's worth noting that, as of a couple years ago, NSF does now have a policy, which is included as another term in their grant contracts, that a copy of any such paper must be given to NSF to be posted on a public website, after a 12-month embargo period. But the grantee still retains the copyright. This is presumably meant as a compromise to provide public access without destroying the existing academic publication system.)