Referring the question to Dr. `Abd al-Fattah Idris, professor of Islamic jurisprudence, he said,
It is permissible to offer salah in this mosque because the hadith in which the Prophet (peace and blessings be upon him) said, “cursed are the Jews and the Christians for they took the graves of their prophets and righteous people as places of worship” prohibits taking the grave of a person as a place of worshiping as a kind of honoring and exalting him. But the mosque you described is surrounded by graves not built on graves.