Praying in a mosque built on a grave is not permissible:
Praying in mosques that have been built over graves is absolutely forbidden. This is unlike the Prophet’s Mosque, in which one prayer carries the reward of a thousand prayers, because its foundation was laid on piety. The Prophet’s Mosque had this lofty rank of virtue and greatness even during the blessed life of the noble Messenger ﷺ, and also in the era of the Rightly-Guided Caliphs, before the blessed chamber was included in it, when the Mercy to the worlds ﷺ himself and the Companions from among the Muhajirun and the Ansar (may Allah be pleased with them) used to pray in it. The virtue and greatness of praying in it that existed in that era remained even after the blessed chamber was included in it. We have already written that the blessed chamber was included in the Prophet’s Mosque in the era of al-Walid ibn Abd al-Malik, when the era of the Companions had ended. Al-Walid took the seat of the caliphate around 80 AH.