All perfect praise be to Allah the Lord of the Worlds. May His peace and blessings be upon our Prophet Mohammad and upon all his family and companions.
What is placed in mosques has multiple situations, and each situation has its own ruling. Here is an explanation of those situations:
1-Whatever people place in mosques for the benefit of others, while intending it as Waqf, is subject to the rulings of Waqf. This is in the sense that it does not belong to anyone and it is not permissible for anyone to dispose of it without a valid reason, regardless of what it may be.
According to the general rule, any item dedicated as Waqf to a specific mosque should remain in that mosque. Moreover, it is not permissible to transfer or sell it except for a valid Islamic reason, out of respect for the donor`s intention. The original case in analogical deduction is that it is not permissible to sell, buy, gift or lend items dedicated as Waqf, as this would obstruct its intended purpose, which is being dedicated for the general benefit of the Muslims. Therefore, if books have been dedicated as Waqf by a specific donor for the benefit of the mosque's library specifically, then these are the rulings regarding them as mentioned above.
2-If books are purchased with donations made by benefactors to the library, and the Waqf administrator has not officially dedicated them as Waqf, then they can be sold and managed for the benefit of the library, even if they haven`t not been damaged yet. In addition, the proceeds can be used for the library's interests.
However, if the Waqf administrator decides to dedicate the books as Waqf, then they take the rulings of Waqf. If they become worn out or equivalent replacements are brought in to serve the same purpose for the worshippers' benefit, then it is permissible to sell or transfer them if it is proven that they cannot be utilized in the same mosque due to their becoming burdensome for the mosque. This is because transferring them to another mosque achieves the purpose of the Waqf even if it is in a different designated location, while not transferring them would result in missing out on utilizing them fully.
Sheikh al-Islam Imam Nawawi, may Allah have mercy on him, said: "If the mosque`s carpets become worn out, its woodwork decays, and the coverings of the Kaaba no longer serve any purpose or beauty, then it is permissible to sell them for two reasons: Firstly, to prevent them from being wasted and to avoid crowding the space without benefit." [Rawdat al-Talibin, Vol. 5/P. 357]. Also, in [I'anat al-Talibin, Vol. 3/P. 215], it is mentioned: "Likewise, transferring items like mosque carpets and lanterns is similar to moving its tools: meaning, if the mosque no longer needs them, it is permissible to transfer them to another mosque; otherwise, it is not permissible."
3-Items donated by authors or others to the library, without specifying them as Waqf, may be sold and used for the library's needs. Imam Nawawi, may Allah have mercy on him, said: "All that we mentioned regarding the mosque`s carpets and similar items applies if the items are dedicated as Waqf specifically to the mosque. However, if the overseer of the mosque purchases or is gifted items and accepts them without specifying them as Waqf, then it is permissible to sell them in cases of necessity without any dispute. This is because they are considered owned property………………...... I say: This is if the administarator purchased the item and did not make it a Waqf. But if he dedicates it as Waqf, then it becomes a Waqf definitively, and the rules of Waqf apply to it." [Rawdat al-Talibin, Vol. 5/P. 358].
4-Items placed in mosques for the convenience of worshippers-such as someone placing a book for their own use in the mosque, without intending it as Waqf or a gift – take the rulings of Ariyah (The gratuitous loan of some object—e.g., a utensil, a tool, or a work animal—to another person for a specific period of time, after which the object is returned to the lender). Therefore, they retain the ownership of their owner, and their placement in the mosque does not change their ownership status.
The Law of Awqaf, Religious Affairs, and Islamic Sanctities, Law No. (32/2001 AD), states in Article (18/A): "The Ministry of Awqaf supervises all mosques and manages their affairs. It also supervises the Quranic centers, Islamic centers, charity houses (Takayas), religious lodges, and their annexes, including those not covered by the ministry's budget, according to a special system issued for this purpose."
In conclusion, it should be noted that the decision on these matters is the responsibility of the authorities in charge of the Waqf funds, which is the Ministry of Awqaf, Religious Affairs, and Islamic Sanctities. They are the ones who decide what is most appropriate and beneficial. And Allah the Almighty knows best.