Is Praying at Graves Permissible?
Question

I was in a conversation with a follower of the Sufi way of Islam and that person asked me what I thought about praying at the graves, or about religious scholars interceding during the day of Judgment. I told that person that praying to someone’s grave is shirk and no one can intercede except the Prophet. What is the ruling of the people of knowledge on this matter and where can I look for proof?
Praise be to Allah.Praying at graveyards 
Praying at graves is of two types: 

The first type is praying to the occupant of the grave . This is major shirk which puts a person beyond the pale of Islam, because prayer is an act of worship, and it is not permissible to do any act of worship to anyone other than Allah. Allah says (interpretation of the meaning): 

“Worship Allah and join none with Him (in worship)” [al-Nisa 4:36] 
“Verily, Allah forgives not (the sin of) setting up partners (in worship) with Him, but He forgives whom He wills, sins other than that, and whoever sets up partners in worship with Allah, has indeed strayed far away” [al-Nisa 4:116]

The second type is praying to Allah in the graveyard. This covers a number of issues: 


Praying the funeral (janazah) prayer at the graveside which is permissible. 

Example: if a person dies and you are not able to offer the funeral prayer for him in the mosque, then it is permissible for you to offer the prayer for him after he is buried. 
The evidence for this is that this is what the Prophet (peace and blessings of Allah be upon him) did. It was narrated from Abu Hurayrah that a black man or a black woman used to clean the mosque, and he (or she) died. The Prophet (peace and blessings of Allah be upon him) asked about them and they said, “They died.” He said, “Why did you not tell me? Show me to their grave.” So he went to the grave and offered the funeral prayer. (Narrated by al-Bukhari, 458; Muslim, 956). 

Praying the funeral prayer in the graveyard which is permissible.

Example: a person dies and you are not able to offer the funeral prayer for him in the mosque, so you go to the graveyard and offer the prayer there before he is buried. 
Shaykh ‘Abd al-Aziz ibn Baz (may Allah have mercy on him) said:
“It is permissible to offer the funeral prayer for the deceased inside the graveyard just as it is permissible to offer the funeral prayer for him after he is buried, because it was proven that a woman used to clean the mosque and she died. The Prophet (peace and blessings of Allah be upon him) asked about her and they said, ‘She died.’ He said, ‘Why did you not tell me? Show me to her grave.’ So they showed him and he offered the prayer for her, then he said, ‘These graves are filled with darkness for their occupants, but Allah illuminates them by my prayer over them.’” (Narrated by Muslim, 956) (From Fatawa al-Lajnah al-Daimah, 8/392) 

Praying in the graveyard – apart from the funeral (janazah) prayer – this prayer is invalid and does not count, whether it is an obligatory prayer or a nafl prayer. 

The evidence for that is as follows: 

The Prophet (peace and blessings of Allah be upon him) said: “All the earth is a mosque apart from the graveyards and bathrooms.” (Narrated by al-Tirmidhi, 317; Ibn Majah, 745; classed as sahih by al-Albani in Sahih Ibn Majah, 606).
The Prophet (peace and blessings of Allah be upon him) said: “May Allah curse the Jews and the Christians, for they have taken the graves of their Prophets as places of worship.” (Narrated by al-Bukhari, 435; Muslim, 529).
Praying in graveyards may be a means that leads to worshipping the graves, or to imitating those who worship graves. Hence, because the kafirs used to prostrate to the sun as it was rising and setting, the Prophet (peace and blessings of Allah be upon him) forbade us to pray when the sun is rising or setting, lest that be taken as a means that leads to worshipping the sun instead of Allah, or to resembling the kuffar.


Praying towards the graveyard, which is haram, according to the correct opinion. 

Example: you pray with a graveyard or grave in the direction of your qiblah, but you are not praying in the graveyard, rather you are praying on some other ground that is close to the graveyard, with no wall or barrier between you and it. 
The evidence for this being haram: 

It was narrated that Abu Marthad al-Ghanawi said: The Messenger of Allah (peace and blessings of Allah be upon him) said: “Do not sit on graves, or pray towards them.” (Narrated by Muslim, 972). This indicates that it is haram to pray towards graveyards or towards graves or towards a single grave.
The reason why it is not allowed to pray towards a graveyard is the same as the reason why it is not allowed to pray towards a grave. So long as a person is facing towards the grave or graveyard in such a way that it may be said that he is praying towards it, then this comes under the prohibition, and if it comes under the prohibition then it is not valid, because the Prophet (peace and blessings of Allah be upon him) said, “Do not pray …” The prohibition here is on praying, so if a person prays towards a grave, he is combining obedience and disobedience, and it is not possible to draw closer to Allah in such a manner.

Note: If there is a wall between you and the graveyard, then the basic principle is that it is acceptable to pray in this case and it is not prohibited. Similarly, if there is a street or a considerable distance which would mean that you cannot be regarded as praying towards the graves, then this is acceptable. And Allah knows best.” (See al-Mughni, 1/403; al-Sharh al-Mumti’ by Ibn ‘Uthaymin, 2/232)
Concept of intercession
You were mistaken when you said that no one will intercede on the Day of Resurrection except the Prophet (peace and blessings of Allah be upon him). Rather the Prophet (peace and blessings of Allah be upon him) will intercede and so will others among the believers. Please see Question no. 11931 . 
But we will add here an issue that was not mentioned there, which is that there are conditions attached to intercession : 

Permission must be granted by Allah to the intercessor to intercede.
Allah must approve of the one for whom intercession is to be made. 

The evidence for these two conditions is the verses in which Allah says (interpretation of the meaning): 
“And there are many angels in the heavens, whose intercession will avail nothing except after Allah has given leave for whom He wills and is pleased with.” [al-Najm 53:26] 
“and they cannot intercede except for him with whom He is pleased.” [al-Anbiya 21:28]
As for the imaginary intercession which the idol-worshippers think their gods perform for them, this is an invalid intercession, for Allah does not permit intercession unless He is pleased both with the intercessor and those for whom intercession is made.  (See al-Qawl al-Mufid Sharh Kitab al-Tawhid by Shaykh Muhammad ibn ‘Uthaymin (may Allah have mercy on him), p. 336-337) 
The fact that the Prophet (peace and blessings of Allah be upon him) and the believers will intercede does not justify asking them to intercede, as some people do when they ask the Prophet (peace and blessings of Allah be upon him) to intercede for them even after his death.
For more, please see these answers: 21394 , 7875 , and 36513 .
And Allah knows best.