Praise be to Allah.
The basic principle is that things that have been donated as a waqf to a specific mosque should not be moved elsewhere, because the one who donated them gave them to that specific mosque, so it is not permissible to move them elsewhere.
Some of the scholars stated that it is permissible – and this is the correct view – to move them to another mosque so long as moving them is more beneficial than leaving them where they are, such as if there are more people who will benefit from them in the second mosque than in the first; or if there is a number of daa’iyahs and seekers of knowledge who will benefit from them and benefit others.
Shaykh al-Islam Ibn Taymiyah (may Allaah have mercy on him) said:
It is permissible to change the conditions stipulated by the waqf donor to something that is more beneficial, even if that varies with time, such as if a person set up a waqf for the fuqaha’, but then the people need jihad, in which case it may be given to the troops. End quote.
Al-Ikhtiyaaraat, p. 176
Shaykh Ibn ‘Uthaymeen (may Allaah have mercy on him) said about changing some conditions stipulated by the donor to something that is better:
This is an issue concerning which the scholars differed. Some of them said that if the donor stipulated conditions in the waqf, but the person in charge thinks that something else is better for the people and will bring a greater reward, then there is nothing wrong with him changing it. Some of them disallowed that and said that this man gave this wealth in a certain manner so it is not permissible to dispose of it except in the manner that he stipulated.
Those who say that it is permissible say that the idea behind waqf is kindness so whatever is kinder is more beneficial to the one who donated the waqf. They quoted as evidence the fact that a man came to the Prophet (peace and blessings of Allaah be upon him) during the year of the conquest (of Makkah) and said: “O Messenger of Allaah, I vowed that if Allaah enabled you to conquer Makkah, I would pray in Bayt al-Maqdis (Jerusalem).” He said: “Pray here.” He repeated what he had said, and (the Prophet (peace and blessings of Allaah be upon him)) said: “Pray here.” He repeated it and he said: “Pray here.” He repeated it and he said, “It is up to you then.”
A waqf is like a vow, so if the Prophet (peace and blessings of Allaah be upon him) permitted the one who had made a vow to change it to that which was better, then the same applies to one who has donated a waqf. This is the correct view, that it is permissible to change the conditions stipulated by the waqf donor to that which is better, so long as the waqf is not donated for the benefit of a specific person. If the waqf is donated for a specific person then it is not permissible to change it to something that is better, because it is specific and the right belongs to a specific person, so it cannot be changed. End quote from al-Sharh al-Mumti’, 9/560, 561
With regard to who has the right to do that, it is the one who is in charge of the waqf, who has been appointed by the one who donated these books as a waqf. If there is no such person, then reference should be made to the body that is responsible for these books, such as the ministry of awqaaf in a Muslim country.
And Allaah knows best.