It depends on the book. The latest Harry Potter was available to most libraries on the day of publication (delivered three or four days in advance), but most, depending on which which supplier the library uses, are available within a couple of weeks.
The reason for the time delay is quite simple - libraries and suppliers need time to service and catalogue the books before they're made available for loan. Now think of the sheer numbers of books the servicing/catalogue offices have to deal with ...
Sometimes, of course, the supplier runs out of stock and we have to wait until more come from the publisher.