because the Prophet (peace and blessings be upon him) said: “Those who came before you used to turn graves into places of worship. Beware—do not turn graves into places of worship, for I forbid you to do so.”
He further ruled that it is not permissible to bury the dead inside a mosque. If the mosque already exists when the burial takes place, the matter must be rectified—either by leveling the grave or, if it is newly dug, by exhuming the body. If, on the other hand, the mosque is built after the grave, then either the mosque must be removed or the visible form of the grave erased. No obligatory or supererogatory prayer may be offered in a mosque built over a grave, for such prayer is prohibited.” See his Fatāwā, 1/107 and 2/192.
Dār al-Iftāʾ of Egypt has adopted this very ruling of Shaykh al-Islam Ibn Taymiyyah, reproducing it in an official fatwa that declares burial inside a mosque impermissible. Anyone who wishes may consult it in Majallat al-Azhar, vol. 11, pp. 501–503 (1).
Ibn Taymiyyah also said in al-Ikhtiyārāt al-ʿIlmiyyah (p. 52): “It is forbidden to light lamps upon graves, and to build mosques over them, …”