Those books are licensed to the libraries by the publishers. The introduction of the opinion here explains how it works:
> This dispute concerns the way libraries lend ebooks. Public and academic libraries in the United States spend billions of dollars each year obtaining print books and ebooks for their patrons to borrow for free. Pls.’ 56.1 ¶ 113. Libraries usually buy their print books from publishers or wholesalers. Id. ¶ 114. Copies of ebooks, however, are typically not bought but licensed to libraries from publishers through distributors called “aggregators.” Id. ¶ 117. The Publishers task aggregators with ensuring that a library lends its ebooks only to the library’s members. Id. ¶¶ 123, 125. The Publishers also require aggregators to employ approved “digital rights management” (“DRM”) software and other security measures to prevent unauthorized copying or distribution of ebook files. Id. ¶ 126.
https://storage.courtlistener.com/recap/gov.uscourts.nysd.53..., page 3 (emphasis added).