Question: If a man or a woman endows a piece of land in the name of a mosque, is it permissible to build houses on it for residence, or shops to be rented out, and the like, or not?
Answer: When a person endows a piece of land in the name of a mosque, it is permissible to build there, as part of the mosque, houses for the residence of the imam, the muadhdhin or the caretaker, or to rent them out so that their rent can be used for the upkeep, repair and the like of the mosque. Likewise, it is also permissible to build shops to rent out, so that the mosque’s expenses can be met from their income. However, it is necessary to take care that the benefit intended in building the mosque is not harmed, for example, that the space for the worshippers and the like does not become cramped.
Reference: Al-Lajnah al-Da’imah: 3505