Ask questions about the position of the connecting verb why.
The question is the second pair, and the linking verb is ahead of the question; If you want to make a clause to express "why they are in the library", you should put the verbs back in their original position and use the first sentence, for example, I want to know why they are in the library.