Yes, a pirated book is often a illegal copy of a legal original. But every copy in a library is legally paid for - and they expect you to return the copies you borrow when you're done with them, because they would have to buy more otherwise. Libraries don't undermine copyright law, they depend on it for their survival.