Sahih Muslim, Book 11, Hadith 66 (Muslim 2166)

Abu Huraira reported Allah's Messenger as saying:

Hasten at a funeral, for if (the dead person) is good, you would (soon) bring him close to the good. And if it is otherwise, it is an evil of which you are ridding yourselves.