This is from the source of a kitab known as ar-Ruh compiled by Ibnu Qayyim the disciple of Ibnu Taimiyyah. The guidelines about are also mentioned in the Fatawa and the Kubra.
Ibnu Taimiyyah when being asked about people who are alive visiting the deceased whether the deceased knows about their visit? Whether they still recognize their family members or those at their funeral?
Ibnu Taimiyyah then answered: "All praises are only to the God. Indeed the deceased do know and realize about this matter. There are many evidences about the meeting of those who are alive with the deceased (souls of the deaths), their discourses, and the practices of those who are alive being shown to those who had passed away."
Ibnu Mubarak from Abu Ayyub al-Ansari mentions that Ibnu Taimiyyah says that: "When the soul of a faithful believer being uprooted from their physical body, those who are blessed by the God (who had earlier passed away) would see him just like those who are alive in the physical world bringing good news to others. They will come to him and greet him. Some of them would say to the others, wait for your brother to rest since he just struggled with the pain of death (leaving the physical body)."
Ibnu Ayyub further narrated: "After the soul resting, other deceased soul would come and talking to him. They would ask about what has been done by this man... what has been done by this woman...?"
The deceased knows that those who are alive visiting him and greeting him with salaam peace prayers. As what has been mentioned by Ibnu Abbas r.a who reported the sayings of prophet Muhammad s.a.w: "A faithful believer who walks at his brothers cemetery and prays with the peaceful greeting to his deceased brothers will be answered by their souls at the cemetery."
Ibnu Mubarak mentioned that, this hadith is valid from the sayings of prophet Muhammad s.a.w through the inspection of Abdul Haqq who compiled the kitaab al-Ahkam (Majmu' Fatawa chap 24 pg. 331).
In other parts, Ibnu Taimiyyah was asked whether the deceased could hear the voice of those who are visiting him and whether he could actually see them? Whether his spirit and soul returns to his body or hovering over his grave? Whether his spirit and soul gathering together with other family members' spirits and souls who had earlier passed away?
He answered: "Praises be to the God, the Lord of the universe. Yes, indeed! The deceased could listen to the voice of people around him as what has been mentioned in the two valids which are the Bukhari and Muslim. The hadith says that the deceased are listening to the clopping sound of shoes made by those who are walking on his grave."
Ibnu Taimiyyah also mentions other evidences from the Sunnah in which showing that the deceased are listening to the sounds around but the physical body could not respond to them. It is not all the time they could hear the sounds. Sometimes they would listen and sometimes not. It is just the same to those who are alive. Those who are alive could also listen to sounds, but sometimes their hearing would be obstructed by obstructions. The hearing sense of the deceased means that they know what happened around them but they could not give any reaction or respond.
It is not referring to the hearing which is denied by the God in Surah an-Naml verse 80. The God says: "Indeed, you (Muhammad and others) could not make those who are dead (their heart is dead) to accept the teachings and lessons." In this verse, the word dead refers to the rejection of the heart and soul of a person (physically and spiritually) to accept the order and decree from the God. Those who are dead refers to those who refused the calling of those who call them toward the God because a dead man could not respond to voices around though he listens to them or simply animals who could listen voices but understand not the meaning of languages (voices). A dead body could listen to the sound and understood what had been said around. But they could not answer or executing whatever had been said.
This verse says that it is of no use to talk to those who are hardened at their heart. It gives no benefit to him or others if we keep talking to him or calling him toward the God. This verse is also in retaliation to verse 23 surah al-Aanfal. The God says: "Had the God knows (because He knows) that there are benefits for them, indeed He would have made them listen. And if He had made them listen, they would have turned away from the Truth." It means that Mercy and Guidance is within His Wisdom and Will. Human-being may pray to Him for guidance and faith.
There are also discussions about this but it is already 'Asr prayer service time. If He wills we would also try to see what are the discussions about this may the God increase our knowledge and faith towards Him, amin!
Sealed with prayers for mercy, peace, and love, amin!