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 . " (Using translation from Bukhārī 1308)
"إِذَا رأى أحدُكُمْ جنازةً فإنْ لم يكُنْ ماشيًا مَعَها فليقُمْ حتى يَخْلُفَها أو تَخْلُفَهُ أو تُوضَعَ مِنْ قَبلِ أنْ تخْلُفَهُ".