@joshisradd – If the idea of a library was brand new in this day and age, then I might agree with you, but since they have existed since before ancient Greece, I don’t think any modern author has any real ground to stand on to protest libraries eating into their profits. It’s just sort of a reality of publishing. The few published authors I know are actually proud to have their work in a local library.
To try to answer the original question, libraries exist and are legal because they predate any and all copyright laws. They predate books themselves because they were around before the printing press was ever invented. The real idea behind the library is the preservation of knowledge. It’s really much more akin to the internet then anything else. Libraries are based on the assumption that knowledge should be readily available and accessible. With the relatively modern advent of copyright law, libraries conform in the ways mentioned above, by prohibiting the duplication of their materials (not that libraries are unique in this way- duplication would be illegal even if libraries didn’t explicitly say so) and they aren’t breaking any laws at all. If there was another organization that had the support that the public library system has and they were dedicated to providing free “rentals” of video games or movies or music- they would be legal as well. Without that support, however, they wouldn’t be able to sustain themselves. Libraries are not a business and do not make money, which is exactly why they are legal.