From Sahih Muslim (Hadith 2186):
Abu Huraira reported Allah's Apostle (ﷺ) as saying:Make haste at a funeral; if the dead person was good, it is a good state to which you are sending him on; but if he was otherwise it is an evil of which you are ridding yourselves
Reference: Muslim 2186