Language:
كتاب الجنائز
23  
Funerals (Al-Janaa'iz)
(67)
Chapter: A dead person hears the footsteps (of the living)
(67)
باب الْمَيِّتُ يَسْمَعُ خَفْقَ النِّعَالِ
Sahih al-Bukhari 1338

Narrated Anas:

The Prophet (ﷺ) said, "When a human being is laid in his grave and his companions return and he even hears their foot steps, two angels come to him and make him sit and ask him: What did you use to say about this man, Muhammad ? He will say: I testify that he is Allah's slave and His Apostle. Then it will be said to him, 'Look at your place in the Hell-Fire. Allah has given you a place in Paradise instead of it.' " The Prophet (ﷺ) added, "The dead person will see both his places. But a non-believer or a hypocrite will say to the angels, 'I do not know, but I used to say what the people used to say! It will be said to him, 'Neither did you know nor did you take the guidance (by reciting the Qur'an).' Then he will be hit with an iron hammer between his two ears, and he will cry and that cry will be heard by whatever approaches him except human beings and jinns."

حَدَّثَنَا عَيَّاشٌ، حَدَّثَنَا عَبْدُ الأَعْلَى، حَدَّثَنَا سَعِيدٌ، قَالَ وَقَالَ لِي خَلِيفَةُ حَدَّثَنَا ابْنُ زُرَيْعٍ، حَدَّثَنَا سَعِيدٌ، عَنْ قَتَادَةَ، عَنْ أَنَسٍ ـ رضى الله عنه ـ عَنِ النَّبِيِّ صلى الله عليه وسلم قَالَ ‏ "‏ الْعَبْدُ إِذَا وُضِعَ فِي قَبْرِهِ، وَتُوُلِّيَ وَذَهَبَ أَصْحَابُهُ حَتَّى إِنَّهُ لَيَسْمَعُ قَرْعَ نِعَالِهِمْ، أَتَاهُ مَلَكَانِ فَأَقْعَدَاهُ فَيَقُولاَنِ لَهُ مَا كُنْتَ تَقُولُ فِي هَذَا الرَّجُلِ مُحَمَّدٍ صلى الله عليه وسلم فَيَقُولُ أَشْهَدُ أَنَّهُ عَبْدُ اللَّهِ وَرَسُولُهُ‏.‏ فَيُقَالُ انْظُرْ إِلَى مَقْعَدِكَ مِنَ النَّارِ، أَبْدَلَكَ اللَّهُ بِهِ مَقْعَدًا مِنَ الْجَنَّةِ ـ قَالَ النَّبِيُّ صلى الله عليه وسلم فَيَرَاهُمَا جَمِيعًا ـ وَأَمَّا الْكَافِرُ ـ أَوِ الْمُنَافِقُ ـ فَيَقُولُ لاَ أَدْرِي، كُنْتُ أَقُولُ مَا يَقُولُ النَّاسُ‏.‏ فَيُقَالُ لاَ دَرَيْتَ وَلاَ تَلَيْتَ‏.‏ ثُمَّ يُضْرَبُ بِمِطْرَقَةٍ مِنْ حَدِيدٍ ضَرْبَةً بَيْنَ أُذُنَيْهِ، فَيَصِيحُ صَيْحَةً يَسْمَعُهَا مَنْ يَلِيهِ إِلاَّ الثَّقَلَيْنِ ‏"‏‏.‏
Reference : Sahih al-Bukhari 1338
In-book reference : Book 23, Hadith 93
USC-MSA web (English) reference : Vol. 2, Book 23, Hadith 422
  (deprecated numbering scheme)