It is narrated from Sayyiduna Abu Qatadah (may Allah be pleased with him) that he said: "Whenever the Messenger of Allah (peace and blessings be upon him) was called to a funeral, he (peace and blessings be upon him) would ask about it (the state of the deceased). If the deceased was praised with good, he (peace and blessings be upon him) would lead the funeral prayer; and if something other than that (evil) was mentioned, he (peace and blessings be upon him) would say: 'You handle his affair yourselves.' And he (peace and blessings be upon him) would not lead his funeral prayer."
Al-Harith bin Abi Usamah, Abu Ya'la, and Ibn Hibban in his Sahih recorded it.