If publishers thought they could get away with closing down the libraries, I don't doubt for one second that they'd try it. They just have the little problem that the concept of public lending libraries pre-dates the modern "where's my money?" era by such a degree that it's effectively grandfathered in. (Same for second-hand bookstores. But boy, you should have heard them yelp when Amazon started listing used books next to new!)
If we take the question seriously, lending books for free in libraries isn't as much of a threat to giving them away free in perpetuity because library books wear out (or expire and require a new purchase after a set number of loans, in the case of library ebooks), and can only be loaned to so many people at once. And they can't be kept forever (unless you crack the DRM on library ebooks, of course), so if you want your own copy of the book you're going to have to buy it. (Or crack the DRM.) There are differences there.