This excerpt is taken from the book of Sheikh al-Islam Imam Ibn Taymiyyah, may Allah have mercy on him, Al-Jawab al-Bahir fi Zuwar al-Maqabir, translated by Sheikh Ataullah Saqib.
Greeting the grave and its response is common
The Companions, may Allah be pleased with them, were well aware that the recommended greeting at the honored grave is the same as the one said during a regular meeting, and it is recommended for every Muslim to say it when meeting his brother or visiting his grave. This greeting includes both the Prophet Muhammad, peace be upon him, and the general believers equally. The Prophet Muhammad, peace be upon him, said:
ما من رجل يسلم على إلا رد الله على روحي حتى أرد عليه السلام
"If anyone sends greetings upon me, Allah will return the soul to my body so that I may respond to his greeting."
Reference: (Sunan Abi Dawood, Book of Pilgrimage: Chapter on Visiting Graves, Hadith: 2040)
And regarding the general believers, it is narrated:
ما من رجل يمر بقبر أخيه المؤمن كان يعرفه فيسلم عليه إلا عرفه ورد عليه السلام
"When a person passes by the grave of his believing brother whom he knew, he greets him, and he recognizes him and responds to his greeting."
Reference: (Reported by Ibn Abdul Barr in Al-Tamhid wal-Istidhkar 1/185 as in Sharh al-Sudur by Al-Suyuti p. 202 and its detailed authentication earlier p. 137)
The Sunnah Supplication for Visiting Graves
The practice of the Holy Prophet Muhammad (peace be upon him) was that when you would visit the graveyard, you would recite this supplication:
السَّلَامُ عَلَيْكُمْ أَهْلَ الدِّيَارِ مِنَ الْمُؤْمِنِينَ وَالْمُسْلِمِينَ وَإِنَّا إِنْ شَاءَ اللَّهُ بِكُمْ لَاحِقُونَ أَنْتُمْ لَنَا فَرَطٌ وَنَحْنُ لَكُمْ تَبَعٌ أَسْأَلُ اللَّهَ الْعَافِيَةَ لَنَا وَلَكُمْ
"Peace be upon you, O inhabitants of the graves! If Allah wills, we shall meet you among the believers and Muslims. You have gone before us, and we are following you. I ask Allah for well-being for myself and for you."
Reference: (Sahih Muslim, Book of Funerals: Chapter on what is said upon entering graves, Hadith: 974, 975)
Prayer with Salah and Salam is superior to Salah and Salam at the grave
You used to teach the Companions, may Allah be pleased with them, this very supplication. During prayer, sending blessings and peace upon you is better than saying it near the honored grave. It is obligatory for every Muslim and a special characteristic of yours. Whoever sends blessings and peace upon you, Allah Almighty sends down mercy upon him. Whoever sends blessings upon the Noble Messenger once, Allah sends down mercy ten times upon him, and whoever says peace once, Allah sends down mercy ten times upon him. Therefore, this purpose is achieved by the Noble Prophet Muhammad, peace be upon him, and his followers when they enter the Prophet's Mosque or any other mosque and send blessings and peace upon the Noble Prophet, peace be upon him. Hence, going near the honored grave does not provide any special benefit to you or to the one who sends peace. However, the Mosque of Quba is an exception because the Companions, may Allah be pleased with them, used to go there every week to demonstrate following the Sunnah. They knew that by attending the Mosque of Quba, they fulfilled the duty of following the Prophet, and by reciting blessings and peace during Friday and other prayers in the Prophet's Mosque, they would earn both rewards simultaneously because praying in the Mosque of Quba grants both benefits at once.
The same applies to the person who goes to visit the graves of the people of Baqi and the martyrs of Uhud, just as the Mercy to the Worlds used to go there and supplicate for them. There is only benefit in this, no harm. Prayers are not made inside the prayer for Jannat al-Baqi and the martyrs of Uhud, which is why visiting their graves is a continuous issue. Nevertheless, it is narrated from Imam Malik, may Allah have mercy on him, that considering it Sunnah is disliked. In this regard, the practice of Ibn Umar, may Allah be pleased with them both, is not obligatory to follow. For example, touching the part of the Prophet's pulpit where the Messenger of Allah used to sit was not considered practical.
The places where the Noble Messenger prayed, Ibn Umar, may Allah be pleased with them both, considered it recommended to go there, and it became his habit to pray there. Despite this, the majority of the Companions, may Allah be pleased with them, did not view it as recommended. The majority of the Companions, may Allah be pleased with them, considered beloved every act that the Messenger of Allah liked, and that is to pray wherever the time for prayer arrives.