Whenever the Messenger of Allah ﷺ was invited to a funeral, he would ask about the deceased. If they were spoken of well, he would stand and pray over them. If they were spoken of otherwise, he would say to the family, "It is your affair," and would not pray over them.
حدثنا يعقوب حدثنا أبي عن أبيه حدثني
كان رسول الله ﷺ إذا دعي لجنازة سأل عنها فإن أثني عليها خير قام فصلى عليها وإن أثني عليها غير ذلك قال لأهلها شأنكم بها ولم يصل عليها
Its isnad is sahih. Yaqub is Ibn Ibrahim bin Saad bin Ibrahim bin Abdul-Rahman bin Awf, a chain of reliable and firmly trusted narrators, and their hadiths, his, his father's, and his grandfather's, are recorded in the Jamaah collections. The hadith has already appeared in similar form at 21569.