It sounds like the books were collected as evidence during a search. All kinds of things can serve as evidence, even if they're not themselves illegal.