source: fataawaa jeddah, tape no. 13/4
Question: “How do we reconcile between the Prophet’s (sallAllaahu ‘alayhi wa sallam) prohibition of praying in the graveyard and his praying over the grave of the woman who used to sweep the mosque?”
Shaikh al-Albaani (rahimahullaah):
“There is no contradiction between the two hadeeths, and all praise is due to Allaah. The first hadeeth with the prohibition of praying in the graveyard is as his (‘alayhi ssalaam) saying in Saheeh Muslim: ‘Don’t sit on graves and don’t pray towards them.’ So the prohibition of praying in the graveyard, i.e. praying towards the graves, is because prayer must be sincerely for the Face of Allaah (tabaarak wa ta’aala) without any glorification for other than Allaah corrupting it or being mixed with it, as that is one type of shirk. So if a Muslim begins to pray to Allaah while facing the grave, there is an obvious suspicion that this person at least intends – as many of the ignorant people do in this era – to seek blessing from this dead person by means of his prayer and by means of his seeking nearness to Allaah (‘azza wa jal) with his prayer. Thus, he has fallen into some shirk, and he may go too far into it such that his situation reaches the point where it would expel him from the circle of Islaam, and refuge is sought in Allaah. This meaning is what should be considered with regard to the Messenger’s (‘alayhi ssalaam) prohibition of praying in the graveyard or praying towards the grave.
As for praying over the dead person while he is in his grave, then this is something else. It has no connection with (the previous situation of) praying to Allaah – Who is alone with no partner – while facing the grave of the dead person, the intention of which is not so that Allaah forgives him, has mercy on him, as is the implied purpose when supplicating over the dead person.
Therefore, praying over the dead person while he is in his grave is one thing, and praying to Allaah (‘azza wa jal) while facing the grave is another thing. This (the latter) is what is prohibited and that (the former) is what is allowed, so there is no contradiction between this and that.”
 Saheeh Muslim #972
 associating partners with Allaah