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.
كان رسول الله ﷺ إذا دعي لجنازة سأل عنها، فإن أنني عليها خير قام فصلى عليها، وإن أثني عليها غير ذلك قال لأهلها: شأنكم بها، ولم يصل عليها.
Imam Ahmad (22555) narrated it from Yaqub, who said, my father narrated to us, from his father, Abdullah bin Abu Qatada narrated to me, from his father, and he mentioned it. Yaqub is Ibn Ibrahim bin Saad. Its chain of transmission is sahih, and Ibn Hibban graded it sahih (3057), as did Hakim (1/364), both of them through the route of Ibrahim bin Saad, with the same wording, and he said, "Sahih according to the criteria of the two Shaikhs."