Libraries can do that. Okay, technically, it's illegal, but under the doctrine of sovereign immunity, since US libraries are run by political subdivisions of US states, they can't be sued with the state's permission which means that a state government can literally not allow the library to be sued for copyright infringement and then they'd get away with it.
The trade-off is that this probably permanently burns all bridges between the library and publishers, who would likely not want to deal with the library any more.
Edit: The controlling US Supreme Court precedent is Allen v. Cooper. The State of North Carolina published a bunch of shipwreck photos. The copyright owner of those photos sued claiming copyright infringement. The Supreme Court ruled in favour of the state saying Congress can't abrogate a state's Amendment XI sovereign immunity using copyright law as a pretext, thus the photography firm needs the State's permission to sue it in federal court.