If the masjid was built on the grave, you must repeat the prayers.
If the grave was introduced to the masjid, some say that as long as it
is not in the direction of qibla, it is ok. I am inclined that praying in that masjid is not permissible as well.