We must distinguish between two similar issues:
1 – Going to a grave and facing it when saying du’aa’ for oneself, seeking blessings and believing that this makes a response more likely. This is undoubtedly an innovation and exaggeration that is forbidden in Islam, and it may lead one to fall into shirk if it leads to one asking the occupant of the grave to meet his needs.
Ibn Taymiyah (may Allaah have mercy on him) said in Majmoo’ al-Fataawa (27/165):
As for visiting graves in order to make du’a’ beside them or to seek to draw closer to Allaah through them (tawassul) or to seek intercession through them, this is not taught by Islam at all. Hence the Sunnah according to the Sahaabah and the imams of the Muslims when a person sends salaams upon the Prophet (peace and blessings of Allaah be upon him) and his two companions (i.e., Abu Bakr and ‘Umar, whose graves are adjacent to that of the Prophet (peace and blessings of Allaah be upon him)) is to say du’aa’ to Allaah facing the qiblah, and not to say du’aa’ facing the grave. I do not know of any imams who disputed the fact that the Sunnah is to face the qiblah at the time of saying du’aa’, and not to face the grave of the Prophet (peace and blessings of Allaah be upon him). End quote.
He also (may Allaah have mercy on him) said in Iqtida’ Siraat al-Mustaqeem (364):
Perhaps what the imams said is based on the fact that it is makrooh to pray facing a grave. The prohibition concerning that is narrated from the Prophet (peace and blessings of Allaah be upon him) as stated above. As it is forbidden to take graves as places of worship or directions of prayer, they were enjoined not to say du’aa’ or pray facing graves. Maalik said in al-Mabsoot: I do not think that one should stand at the grave of the Prophet (peace and blessings of Allaah be upon him) and say du’aa’, rather one should say salaam and move on.
This is well-established principle. It is not recommended for the one who is saying du’aa’ to face any direction except the one that is recommended when praying. Do you not see that as the Muslim is forbidden to pray facing east or any other direction, he is also forbidden to face those directions when saying du’aa’. Some people, when saying du’aa’, try to face the direction in which the righteous man whom he venerates is, whether that is in the east or elsewhere. This is obvious misguidance and clear shirk. End quote.
When the Muslim worships Allaah by saying du’aa’, it is mustahabb for him to face towards the Qiblah which we are enjoined to venerate, not towards the graves of human beings who cannot bring benefit to or ward off harm from themselves.
It says in Kashshaaf al-Qinaa’ (1/367), which is a Hanbali book:
The one who is saying du’aa’ should face towards the qiblah because the best of gatherings is that which faces towards the qiblah. End quote.
It says something similar in the commentary on Tuhfat al-Muhtaaj (2/105), which is a Shaafa’i book.
Ibn Taymiyah (may Allaah have mercy on him) said in Naqd al-Ta’sees (2/452):
The Muslims are unanimously agreed that the qiblah which it is prescribed for the one who is saying du’aa’ to face when saying du’aa’ is the qiblah which it is prescribed to face when praying. End quote.
2 – When visiting a grave to pray for its occupant and pray for forgiveness for him, as people do when they visit their dead loved ones in their graves, there is nothing wrong with facing the gave when saying du’aa’ in this case, because he is not doing that to seek blessing from that grave or to venerate it. Rather he does that so as to be physically closer to the deceased and closer in his du’aa’.
Shaykh ‘Abd al-‘Azeez ibn Baaz (may Allaah have mercy on him) was asked the following question (13/338):
Is it forbidden to face the grave when saying du’aa’ for the deceased?
He (may Allaah have mercy on him) replied:
That is not forbidden, rather one may say du’aa’ for the deceased facing the qiblah or facing the grave, because the Prophet (peace and blessings of Allaah be upon him) stood over graves after the burial and said: “Pray for forgiveness for your brother and ask that he be made steadfast, for even now he is being questioned.” Narrated by al-Bukhaari.
And he did not say to face the qiblah. So both are permissible, whether one faces the qiblah or the grave. The Sahaabah (may Allaah be pleased with them) prayed for the deceased when they were gathered around the grave. End quote.
And Allaah knows best.