Praise be to Allah, the Lord of the Worlds; and may His blessings and peace be upon our Prophet Muhammad and upon all his Family and Companions.
The Prophet (Sallallahu Alaihi wa Sallam) said: "May Allah curse the Jews and Christians for they built places of worship at the graves of their Prophets." [Al-Bukhari and Muslim]
Imam Muslim reported from Jundub Bin Abdullah al-Bajali that the Prophet (Sallallahu Alaihi wa Sallam) said: "Beware! That those who were before you, used to turn the graves of their Prophets and pious people into places of worship, beware of turning graves into places of worship. I forbid you doing that".
Therefore, performing prayers in the mosques with graves inside them is not allowed. However, if the graves are outside the mosque, at the right or the left side, or in front of the mosque or behind it, hence they are valid.
Allah knows best.