The First Matter”: Do the dead recognize those who visit them and also hear their greetings or not? Ibn Abdul Barr said that It is proven from the Messenger of Allah (Peace be upon him) that he said: Any Muslim who passes by the grave of his brother whom he knew in worldly life and offers him a greeting then Allah returns the soul back to him and he responds to the greeting
[Imam Ibn Abdul Barr narrated it in Al-Tamhid with an authentic (Sahih) chain, Imam Abdul Haq declared it Sahih as is narrated in Faidh ul Qadeer (5/487), Imam Iraqi in Takhrij of Ihya uloom ud-din (4/522), Sharh as Sudoor by Hafidh as-Suyuti, Page No. 273, declared as Sahih in Takhrij of Kitab ar Ruh Published by Dar Ibn Kathir, Damuscus, Page No. 53]
Hence this is a definite proof (Nass) that dead recognize the visitor and also reply to the greeting. It is narrated with multiple chains in Sahihayn (i.e. Bukhari and Muslim) that on order of the Prophet (May Peace be upon him) a well was dug for the dead of Badrafter which the Prophet (May Peace be upon him) stood nearby and called them out as: “Ya Fulan ibn Fulan (i.e. O Son of so-and-so”) wa-Ya Fulan ibn Fulan, have you not found what your Lord had promised with you to be correct? As for me, I have found the promises of my Lord to be (perfectly) correct, Umar (May Allah’s Mercy be upon him) said: O Allah's Messenger, you are speaking to bodies which have no souls! Thereupon he (the Holy Prophet) said: By Him in whose hands is Muhammad’s soul, what I am saying to them, even you cannot hear more distinctly than they, but they lack the power to reply.
[Narrated in Sahih Bukhari (7/300-301) and narrated in Sahih Muslim Hadith # 2873 – Agreed upon] (Next Page # 54): It is also proven from the Messenger of Allah (Peace be upon him) that when people return after burying the dead then he (even) hears the sound of their footsteps. [Narrated in Sahih Bukhari (3/305) in the book of Funerals, also Sahih Muslim Hadith # 2870, Sunnan Nasai’i (4/96-97) and others]
Other than this the Prophet (May Peace be upon him) has taught his Ummah to say Salaam to the people of graves by addressing them directly i.e. Peace be upon you O Believers of the abode.
[Sahih Muslim Hadith # 249 in the book of Purification]
This type of address is only made to a person who can hear and understand, otherwise it is just like addressing someone who is not present or something which is an inanimate object (which is not correct). “The Islaaf (early Muslims) had Ijma (consensus) upon this matter and It has also come as “Tawatur (i.e. definitely known)” that dead recognize the alive people who visit them and also become happy”
[Kitab ar-Ruh by Ibn Qayyim, Page Nos. 53-54]