Sayyiduna al-Bara' bin Azib (may Allah be pleased with him) says: "The Messenger of Allah (peace and blessings be upon him) ordered us to follow funerals (that is, to take part in them)."
It is narrated from Sayyiduna Abu Hurayrah (may Allah be pleased with him): I heard the Messenger of Allah (peace and blessings be upon him) say: "The Muslim has five rights over the Muslim: returning the greeting of salam, visiting the sick, following funerals, accepting an invitation, and responding to one who sneezes."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجنائز / 6616