All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
First of all, you should know, dear brother, that we must have a correct and clear perception of the location of the mosque and the location of the grave so that we can give an appropriate ruling on it. In our view, what you have mentioned is not enough to show us the matter clearly.
In any case, what we can say now based on our perception (of the location) is that regarding the first mosque, where the grave is located outside it, it is permissible to pray in it as long as the grave is separated from the mosque by the wall of the mosque – as we understood from the question. This is the view we adopt here in Islamweb. However, even though we are of the view that it is permissible to pray in this case, we do not object to your friend’s refraining from praying in it as he might have adopted the view of the scholars who say that the wall of the mosque is not enough in itself, or that he does not want to pray in it out of piety or in order to be on the safe side.
There is no doubt that in order to be on the safe side, it is better to build another wall other than the wall of the mosque as some jurists are of the view that the wall of the mosque is not enough (in this case); this is one of the two narrations by Ahmad .
“Mataalib Ouli An-Nuha”, which is one of the Hanbali books, reads: "The wall of the mosque is not enough as explicitly stated by Imaam Ahmad ; this is what was authoritatively asserted by a group of scholars, among whom are Al-Majd, Ibn Tameem, and An-Naathim (the author of the Hanbali Fiqh poem) and others, and this view of Imaam Ahmad was the preponderant view according to the author of "Ar-Ri’aayatayn” ( i.e. the two books: Ar-Ri’aayah Al-Kubra and Ar-Ri’aayah As-Sughra) and the author of the "Al-Haawiyayn” (i.e. the two books: Al-Haawi Al-Kabeer and Al-Haawi As-Sagheer) and others, as the Salaf (righteous predecessors) are of the view that it is disliked to pray in a mosque whose Qiblah is a toilet...” [End quote]
However, in case no other wall is built other than the wall of the mosque, then we hope that it is permissible to pray in it and the wall of the mosque is enough according to the view we adopt in Islamweb. Shaykh Ibn 'Uthaymeen was asked: “What is the ruling if it is only the wall of the mosque that separates between the cemetery and the mosque?; and he answered: “If the cemetery is on the right side of the praying person or on his left side or behind him, then this is permissible..... But if the graves are in the direction of the Qiblah, then this is a very serious matter and if not for the wall of the mosque which separates between the mosque and the graves, we would say that the prayer is absolutely invalid, because the Prophet said: "Do not pray facing towards the graves.” For more benefit, please refer to Fataawa 89719 and 87303.
As regards the second mosque, where a half body length wall separates it from the cemetery, in addition to the wall of the mosque, while there are windows in the wall of the mosque through which the praying people can see the graves; then in our view it is disliked to pray in it for two reasons:
- The first reason is that the scholars differed in opinion in regard to a short wall whether or not it is enough as a barrier (between the mosque and the graveyard). Some jurists are of the view that it is not enough; Shaykh Ibn 'Uthaymeen said: “If there is a cemetery around the mosque but there is a wall separating between them, then it is permissible to pray in it unless the wall is short in a way that the person who prays in it looks like he is praying to the grave, then this is forbidden. The prayer in these places is not valid.”
Also, in ‘The Open Door’ meeting, Shaykh Ibn 'Uthaymeen said: “If a person prays in a mosque in front of which there is a cemetery, then if there is a separation between them, like a street for example, or a complete wall, in a way that the praying people do not see the cemetery, then this is permissible. But if the cemetery is near immediately after the mosque, and there is no wall separating them or that there is a wall but it is short, in a way that the praying people see these graves, then this is not permissible; because the Prophet said: "Do not pray facing towards the graves and do not sit on them.”
However, the Hanbali scholars permitted the prayer with the existence of a short barrier. Ar-Ruhaybaani the author of “Mataalib Ouli An-Nuha” said: “If there is a barrier (i.e. between the graves and the mosque), the prayer is not disliked, even if it is the height of the rear end of a camel’s saddle which a person who wants to relieve himself takes…”
Moreover, Al-Mardaawi said in his book entitled “Al-Insaaf” about the height of the barrier with which the prayer (in this case) is valid: “... even if it is only like the rear end of a camel’s saddle, the prayer is valid according to the correct opinion of the Hanbali School….”
- The second reason is that the praying people seeing the graves in front of them through the windows while praying renders the cause of prohibition existent; it is for this reason that Shaykh Al-Albaani in his book entitled “Tahtheer As-Saajid” said: "The appearance of the grave in the mosque, even from behind windows, iron (barrier) and doors does not remove the cause of prohibition.”
To conclude, your two friends are not wrong to refrain from praying in the two mosques which you mentioned in the question. For more benefit, please refer to Fatwa 147941.
Allaah Knows best.