The answer given to the question by His Eminence, Ayatollah Mahdi Hadavi Tehrani is as under:
If the land is not endowed specifically for graveyard and if the mosque is built in such a way that it does not hinder burial (for example, it is built at a higher place), and there is also no prohibition on the part of the endower, there is no problem in constructing a mosque there. Of course, if the land is endowed specifically for burial and building a mosque hinders burial, it is not permissible to build a mosque in the graveyard. In case, for some reason the land can no longer be used as graveyard, i.e. it is close to a residential area and it is likely that pollution may spread out to other places, the land that cannot be used for graveyard can be used, with the permission of a qualified jurist, to construct a mosque in it.