Abu Hurayrah (may Allah be pleased with him) reported that the Messenger of Allah (may Allah's peace and blessings be upon him) said: "Whenever someone greets me, Allah restores my soul to me so that I return his greeting."
عن أبي هريرة -رضي الله عنه- عن النبي -صلى الله عليه وسلم- قال: «ما من أحد يُسَلِّمُ عليَّ إلا ردَّ الله عليَّ روحي حتى أرُدَّ عليه السلام».
شرح الحديث :
This Hadīth indicates that whenever anyone greets the Prophet (may Allah's peace and blessings be upon him) Allah returns the Prophet's soul to him so that he greets that person back. Apparently, this applies to those who are close to the Prophet, such that they stand close to his grave and greet him by saying: "May the peace, mercy and blessings of Allah be upon you, O Prophet." It is also possible that it applies in general. Indeed, Allah is over all things Competent.