This excerpt is taken from Sheikh al-Islam Imam Ibn Taymiyyah's book Al-Jawab al-Bahir fi Zuwar al-Maqabir, translated by Sheikh Ataullah Saqib.
Prayer in a mosque built over a grave is not permissible:
Praying in mosques that are built over graves is absolutely forbidden. This is unlike the Prophet's Mosque, in which the reward for one prayer is equal to that of a thousand prayers. This is because its foundation was laid on piety. The Prophet's Mosque held this high status of virtue and greatness even during the blessed life of the Messenger of Allah, peace be upon him. Before the inclusion of the Blessed Chamber in it, during the era of the Rightly Guided Caliphs, when the Mercy of the Worlds, peace be upon him, and the Muhajirin and Ansar companions, may Allah be pleased with them, used to pray in it. The virtue and greatness of praying in it during that time remained even after the Blessed Chamber was included in it. As we have mentioned before, the Blessed Chamber was incorporated into the Prophet's Mosque during the time of Walid bin Abdul Malik, when the era of the companions had ended. Walid ascended the caliphate throne around 80 AH.