The Friends are a separate nonprofit from the library, usually run by volunteers. They can also accept donations from the public, keeping books out of dumpsters. They organize regular book sales which are generally popular with the reading public.
https://action.everylibrary.org/from_book_sales_to_big_impac...
If you think that books should be kept out of the landfill or the shredder, please consider starting a Friends group for your local library.
https://www.ala.org/united/friends