Sheikh Muhammad al-Manî`î, professor at Umm al-Qurâ University
The mosque comes under the rule of endowments. The majority of scholars hold the view that it may not be sold or transferred unless it ceases to be used.
In the Hanbalî legal work al-Rawd al-Murbi`, it states: “An endowment is a contract which is executed by the mere utterance of it, even if it was not officiated by the ruler or the judge (as in the case of manumission) on the basis of the Prophet’s (peace be upon him) saying: ‘It cannot be sold, granted or inherited.’ …It cannot be sold or replaced unless it becomes useless."
Ibn Taymiyah says: “Endowment may be sold or replaced when usage is minimized.”
Ibn Taymiyah and his student Ibn al-Qayyim held the opinion that replacement for a greater benefit is lawful provided it is issued in the favor of the guardian of the endowment by the endowment grantor or any official authority.
Ibn Taymiyah says: “Regarding the mosque it is lawful to sell it if there is a need to do so, in accordance with the most famous opinions of Imam Ahmad... Abu `Abd Allah (Ahmad) was asked: Could a mosque be transferred? He replied: In case it is small and does not accommodate the worshippers, it is alright to transfer it to a more spacious location.” [Majmû` al-Fatâwâ (31/212)]
Therefore, on the basis of the opinions of Ahmad b. Hanbal and Ibn Taymiyah, I believe you can sell the mosque for the purpose of constructing a new one, if the location was not good or it is area was small, for the purpose of having more capacity. The price obtained from selling the first mosque will be used for buying the new mosque with the addition of whatever donations may be collected.
However, the old mosque should not be sold until proper assessment is made of its salable value and it is determined that this value along with any further donations will be sufficient to pay for the new mosque.
Source: Islam Today