All perfect praise be to Allaah, The Lord of the worlds. I testify that there is none worthy of worship except Allaah and that Muhammad is His slave and Messenger.
If we presume that this land is endowed for building a mosque on it and the matter is as you mentioned, that the mosque was built at another place that is better for the people, and there is no need for building a mosque on that piece of land, then we do not see any harm in benefiting from this land in any other way as the necessity may require.
Shaykh Ibn Taymiyyah said:
“As for changing the form of construction without any transgression, then this depends on the benefit. So if this method is better for the endowment and the people, then it is approved, and if rebuilding it as it was before is better, then it should be rebuilt. If there is a third way of building it that is best for the endowment, then it should be rebuilt accordingly. So in the form of building, the benefit of the endowment is taken into account, and the benefit is opted for wherever it is. Indeed, it is confirmed that the Rightly-guided Caliphs, ‘Umar and ‘Uthmaan had changed the form of an endowment for the greater interest; rather, ‘Umar ibn Al-Khattaab went so far as to change the old mosque of Al-Koofah to a market for selling dates, and he built a mosque for the people in another place.”
For more benefit, please refer to fataawa 229822 and 117368.
Allaah knows best.