Anas bin Malik reported,

A funeral procession passed by, and the people praised the deceased with good words. The Prophet of Allah ﷺ said, "It is confirmed, it is confirmed, it is confirmed."Then another funeral procession passed by, and the people spoke ill of the deceased. The Prophet of Allah ﷺ said, "It is confirmed, it is confirmed, it is confirmed."Umar said, "May my father and mother be ransomed for you. A funeral passed by and the people praised the deceased with good words, and you said, 'It is confirmed, it is confirmed, it is confirmed.' Then another funeral passed by and the people spoke ill of the deceased, and you said, 'It is confirmed, it is confirmed, it is confirmed.'"The Messenger of Allah ﷺ replied, "Whoever you praise with good, Paradise is confirmed for him, and whoever you speak ill of, the Fire is confirmed for him. You are Allah's witnesses on earth, you are Allah's witnesses on earth, you are Allah's witnesses on earth."

Muslim 2200

Sahih

و حدثنا يحيى بن أيوب وأبو بكر بن أبي شيبة وزهير بن حرب وعلي بن حجر السعدي كلهم عن ابن علية واللفظ ليحيى قال حدثنا ابن علية أخبرنا عبد العزيز بن صهيب

عن أنس بن مالك قال

مر بجنازة فأثني عليها خيرا فقال نبي الله ﷺ وجبت وجبت وجبت ومر بجنازة فأثني عليها شرا فقال نبي الله ﷺ وجبت وجبت وجبت قال عمر فدى لك أبي وأمي مر بجنازة فأثني عليها خير فقلت وجبت وجبت وجبت ومر بجنازة فأثني عليها شر فقلت وجبت وجبت وجبت فقال رسول الله ﷺ من أثنيتم عليه خيرا وجبت له الجنة ومن أثنيتم عليه شرا وجبت له النار أنتم شهداء الله في الأرض أنتم شهداء الله في الأرض أنتم شهداء الله في الأرض

مسلم 2200صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Funerals
Chapter
Those among the dead who are praised with good or evil
Numbering
Darussalam 2200
Muslim 2200