Accompanying the corpse, and attend the funeral procession is a valid case of the Prophet sallallahu'alaihi wasallam, as mentioned in saheeh hadeeth from Abu Hurairah radiyallahu anhu that Rasulullah sallallahu'alaihi wasallam said,
"The obligation of a Muslim against another Muslim is to answer greetings, visit the sick, accompany the body, fulfill the invitation, and pray for the sneeze." (Narrated by al-Bukhari and Muslim).
So also in another hadith from Abu Hurairah radiyallahu 'anhu that Rasulullah sallahu'alaihi wasallam said,
"Whoever sees the corpse to his senses, then for him is a qirath (mountain), and whoever witnesses it is buried, then for him two qirath, it is said, 'What are two qirath?', He replied, 'Like two great mountains.'" (HR al-Bukhari and Muslim).
It should be a Muslim who attends the corpse while accompanying and burying him, to make the calamity of death as a memorial to him, and to take wisdom and contemplate on the body, and indeed the person who accompanies the corpse, will someday be like the corpse he is in.
Taking the wisdom and making it a warning in this event will motivate people to introspect themselves, reflect and think in every condition. If he is a good person, then his goodness will increase, and if he is a bad person, he will repent and get right to the right direction.
These reflections and warnings are the purpose of attending the corpse, as described in the hadith of Abu Said al-Khudri radhiyallahu 'anhu that the Prophet said,
"Go to the sick, and go to the dead, and will remind you of the Hereafter." (Narrated by Ahmad and Ibn Hibban, almighted by al-Albani in "Ahkamu al-Jana'iz: 67).
And narrated in another hadith,
"That the Prophet sallallahu'alaihi wasallam when accompanying the corpse, reproduce silent, and he looks mourning, and reproduce the reflection." (HR Waki 'in' Az-Zuhud '),
and this hadith has a shahih martyr, from al-Barra 'bin' Azib radhiyallahu 'anhu, he said,
"We went out with the Messenger of Allah to accompany the corpse, so we came to the grave, and then he sat as if a bird were above our heads." (Ibn Majah, spelled out by al-Albani, see Sahih Sunan Ibn Majah 1 / 259, and see al-Misykah 15/537).
Al-Fudhail bin Iyadh rahimahullah said, "When they gather in order to mourn the corpse, then the popular of them is only three days". Abdullah ibn mas'ud radhiyallahu 'anhu had seen someone laugh during the procession of the corpse, saying, "Are you laughing at the corpse's rope! I will not talk to you forever ".