The Messenger of Allah ﷺ said, "When you see a funeral procession, stand up for it until it passes you or is set down."
قال رسول الله ﷺ: إذا رأيتم الجنازة فقوموا لها، حتى تخلفكم، أو توضع.
Bukhari narrated it in the Book of Funerals (1307), and Muslim in the Book of Funerals (958), both through Sufyan, from Zuhri, from Salim, from his father, from Amir bin Rabia, and he related the hadith, and their wording is the same. Bukhari (1308) and Muslim also both narrated it from Qutayba bin Saeed, who said, Layth bin Saad narrated to us, from Nafi, from Ibn Umar, from Amir bin Rabia, with this wording, "When one of you sees a funeral procession, if he is not walking with it, he should stand until it passes him, or he passes it, or it is set down before it passes him."