Sunan an-Nasa'i, Book 21, Hadith 116 (In-Book)

It was narrated that Anas said: "A funeral passed by and the deceased was praised." The Prophet said: "It is granted." Another funeral passed by and the deceased was criticized. The Prophet said: "It is granted." 'Umar said: "May my father and mother be ransomed for you. One funeral passed by and the deceased was praised, and you said, 'It is granted?"' He said: "Whoever is praised will be granted Paradise, and whoever is criticized will be granted Hell, You are the witnesses of Allah on Earth."

أَخْبَرَنِي زِيَادُ بْنُ أَيُّوبَ، قَالَ حَدَّثَنَا إِسْمَاعِيلُ، قَالَ حَدَّثَنَا عَبْدُ الْعَزِيزِ، عَنْ أَنَسٍ، قَالَ مُرَّ بِجَنَازَةٍ فَأُثْنِيَ عَلَيْهَا خَيْرًا فَقَالَ النَّبِيُّ صلى الله عليه وسلم ‏"‏ وَجَبَتْ ‏"‏ ‏.‏ وَمُرَّ بِجَنَازَةٍ أُخْرَى فَأُثْنِيَ عَلَيْهَا شَرًّا فَقَالَ النَّبِيُّ صلى الله عليه وسلم ‏"‏ وَجَبَتْ ‏"‏ ‏.‏ فَقَالَ عُمَرُ فِدَاكَ أَبِي وَأُمِّي مُرَّ بِجَنَازَةِ فَأُثْنِيَ عَلَيْهَا خَيْرًا فَقُلْتَ ‏"‏ وَجَبَتْ ‏"‏ ‏.‏ وَمُرَّ بِجَنَازَةٍ فَأُثْنِيَ عَلَيْهَا شَرًّا فَقُلْتَ ‏"‏ وَجَبَتْ ‏"‏ ‏.‏ فَقَالَ ‏"‏ مَنْ أَثْنَيْتُمْ عَلَيْهِ خَيْرًا وَجَبَتْ لَهُ الْجَنَّةُ وَمَنْ أَثْنَيْتُمْ عَلَيْهِ شَرًّا وَجَبَتْ لَهُ النَّارُ أَنْتُمْ شُهَدَاءُ اللَّهِ فِي الأَرْضِ ‏"‏ ‏.‏

sunnah.com