Narrated ‘Amir bin Rabi’a:,
The Prophet said, “Whenever you see a funeral procession, stand up till the procession goes ahead of you.” Al-Humaidi added, “Till the coffin leaves you behind or is put down.”
Narrated ‘Amir bin Rabi’a:
The Prophet said, “If any one of you see a funeral procession and he is not going along with it, then he should stand and remain standing till he gets behind it, or it leaves him behind, or the coffin is put down before it goes ahead of him . “
Narrated Said Al-Maqburi:
That his father said, “While we were accompanying a funeral procession, Abu Huraira got hold of the hand of Marwan and they sat down before the coffin was put down. Then Abu Said came and took hold of Marwan’s hand and said, “Get up. By Allah, no doubt this (i.e. Abu Huraira) knows that the Prophet forbade us to do that.” Abu Huraira said, “He (Abu Said) has spoken the truth.”
Narrated Abu Said Al-Khudri
The Prophet said, “When you see a funeral procession, you should stand up, and whoever accompanies it should not sit till the coffin is put down.”
Narrated Jabir bin ‘Abdullah :
A funeral procession passed in front of us and the Prophet stood up and we too stood up. We said, ‘O Allah’s Apostle! This is the funeral procession of a Jew.” He said, “Whenever you see a funeral procession, you should stand up.”
Narrated ‘Abdur Rahman bin Abi Laila:
Sahl bin Hunaif and Qais bin Sad were sitting in the city of Al-Qadisiya. A funeral procession passed in front of them and they stood up. They were told that funeral procession was of one of the inhabitants of the land i.e. of a non-believer, under the protection of Muslims. They said, “A funeral procession passed in front of the Prophet and he stood up. When he was told that it was the coffin of a Jew, he said, “Is it not a living being (soul)?”
Following funeral processions of believers is recommended. Men must try and attend the funeral prayer and/or the burial after it. Lots of reward promised for it.
As for the last two narrations, Ali (RA) said about them that Prophet (SAW) did it only once. After this, the hukm came to not follow the non-Muslims in any of their practices. So this action of the Prophet (SAW) – standing for the funeral procession of a Jew – got abrogated. It is not allowed for a Muslim to attend the funeral procession / prayer / burial of a non-Muslim.
If there are people among the kuffaar who can bury their own dead, then the Muslims should not bury them, or join the kuffaar and help them to bury them, or try to please the kuffaar by joining the funeral procession, even if this is a political practice. Such things are not known from the Messenger of Allaah (peace and blessings of Allaah be upon him) or the Khulafaa’ al-Raashidoon. In fact, Allaah forbade His Messenger (peace and blessings of Allaah be upon him) to stand by the grave of ‘Abd-Allaah ibn Ubayy ibn Salool, and explained that the reason for this prohibition was that the man was a kaafir. Allaah said (interpretation of the meaning):
“And never (O Muhammad) pray (funeral prayer) for any of them (hypocrites) who dies, nor stand at his grave. Certainly they disbelieved in Allaah and His Messenger, and died while they were Faasiqoon (rebellious, — disobedient to Allaah and His Messenger).” [al-Tawbah 9:84]
If there is nobody among them who can bury their dead, then the Muslims should bury them, as the Prophet (peace and blessings of Allaah be upon him) did with those who were killed at Badr, and as he did with his uncle Abu Taalib, when he died, and he [the Prophet (peace and blessings of Allaah be upon him)] said to ‘Ali: “Go and bury him.”
[Taken from IslamQA]
More details here.