All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
Stealing books is forbidden just like stealing other things, but if a person reads them and benefits knowledge from them, then it is permissible for him to benefit from the book’s knowledge, and he will have the sin of stealing it and he has to compensate what he damaged to its owner from those books. As for what he learned from them of useful sciences, he may benefit from them in his worship or work.
Allah knows best.