Abu Qatada reported,

Whenever the Messenger of Allah ﷺ was called to a funeral, he would ask about the deceased. If the person was spoken of well, he would stand and pray over them. If the person was spoken of otherwise, he would say to the family, "It is your affair," and would not pray over the deceased.

Azami 3644

Sahih

عن أبي قتادة قال

كان رسول الله ﷺ إذا دعي لجنازة سأل عنها، فإن أنني عليها خير قام فصلى عليها، وإن أثني عليها غير ذلك قال لأهلها: شأنكم بها، ولم يصل عليها.

الأعظمي 3644صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Funerals
Chapter
Deceased, carrying the funeral bier, and standing for it
Section
Praise of the people for the deceased
Numbering
Jami al-Kamil 3644 (2nd edition)
Azami 3644