From this ḥadith one may also infer the permissibility of repeating the funeral prayer for the deceased—even by someone who has already prayed over him—when he comes upon another congregation, for it seems that those who accompanied the Prophet ﷺ on that occasion prayed with him. Accordingly, it is prescribed to repeat the congregational funeral prayer if a second group performs it.
Some scholars have adopted this position, saying: just as an obligatory prayer may be offered again when you have already performed it but then find another congregation, so too may the funeral prayer be repeated. Thus, if someone prayed over a bier in the mosque and the body was then taken to the cemetery where another group formed to pray, there is no harm—indeed, no reprehensibility—in joining that second congregation and repeating the prayer. The repetition here is purposeful; it is not a mere duplication but is occasioned by the presence of the new congregation.
If someone were to ask, “When I pray at the grave, where do I stand?” the answer is: stand behind it, making the grave itself come between you and the qiblah, just as you would have done had you prayed over the deceased before burial.
6/257 — Abu Hurayrah reported that the Messenger of Allah ﷺ said: “Many a shaggy, dusty man who is turned away from people’s doors—were he to swear an oath by Allah, Allah would certainly fulfill it.” Narrated by Muslim.
7/258 — Usāmah reported that the Prophet ﷺ said: “I stood at the gate of Paradise and saw that most of those who entered it were the poor, whereas those possessing wealth were detained, except that—”