Anas bin Malik reported,

A funeral procession passed by, and the people praised the deceased with good words. The Prophet ﷺ said, "It has become certain."Then another funeral passed by, and they spoke ill of the deceased. The Prophet ﷺ said, "It has become certain."Umar bin Khattab رضي الله عنه asked, "What has become certain?"He replied, "This one whom you praised with good, Paradise has become certain for him. And this one whom you spoke ill of, the Fire has become certain for him. You are Allah's witnesses on earth."

Bukhari 1367

Sahih

حدثنا آدم حدثنا شعبة حدثنا عبد العزيز بن صهيب قال سمعت

أنس بن مالك رضي الله عنه يقول

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

البخاري 1367صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Funerals
Chapter
Praise of the people for the deceased
Numbering
Darussalam 1367
Bukhari 1367