this is prescribed for all deceased Muslims, just as it is recommended to greet them with peace, supplicate for them, and seek forgiveness for them.
Visiting graves for this purpose is recommended, whether they are the graves of prophets, righteous people, or others. When Abd Allāh ibn Umar entered the mosque, he would say:
“Peace be upon you, O Messenger of Allah. Peace be upon you, O Abū Bakr. Peace be upon you, O my father.”
Then he would leave.
As for visiting the graves of prophets and righteous people to ask them to fulfil one’s needs, invoke them, adjure Allah by them, or out of a belief that supplication or prayer at their graves is better than in mosques and homes, this is misguidance, associating partners with Allah, and religious innovation, by agreement of the leading Muslim scholars. None of the Companions used to do this. Nor, after greeting the Prophet—may Allah bless him and grant him peace—would they remain standing to supplicate for themselves. For this reason, Mālik and other scholars disapproved of this and said that it was among the innovations not practised by the early generations.
The four imams and others among the early generations agreed that anyone wishing to supplicate should face the direction of prayer, not the grave of the Prophet—may Allah bless him and grant him peace. When greeting him, however, most of them said that one should face the grave. This was the position of Mālik, al-Shāfi‘ī, and Ahmad. Abū Hanīfah said that one should instead face the direction of prayer in this case too, with the grave to one’s left. Another view is that one should instead turn one’s back to the direction of prayer.
Further illustrating this principle is the fact that when the Messenger of Allah—may Allah bless him and grant him peace—and Abū Bakr emigrated, they went to the cave on Mount Thawr, which was not on their route