It is permissible to offer funeral prayer for a deceased anytime after his burial, even if a prayer was offered prior to his burial. As mentioned above, the Prophet, peace be upon him, offered funeral prayer for the martyrs of Uhud after eight years. Zaid ibn Thabit reported: “Once we went out with the Prophet, peace be upon him. When we reached al-Baqi’ (Famous cemetery in Madinah, where a large number of the Prophet’s companions are buried) we noticed a newly dug grave. The Prophet, peace be upon him, asked about it and was told that was the grave of such and such a woman. At this he said: ‘Why did you not inform me of her death?’ They replied, ‘O Prophet of Allah! You were fasting and were resting at the time and we did not want to bother you.’ He said: ‘Do not do that again. So long as I am with you, make sure you inform me when any one among you dies, for my prayers for the deceased is a mercy for them.’ Then the Prophet, peace be upon him, went to the grave. We stood in rows behind him and he offered a funeral prayer for her with four takbirs.” This hadith has been reported by Ahmad, Nasa’i, Al-Baihaqi, Al-Hakim and Ibn Hibban. The last two reporters regard it as a sound hadith.
Tirmizhi said: This has been the practice of most of the scholars, the Companions of the Prophet (may Allah be pleased with them), as well as others. Ash-Shafi’i, Ahmad, and Ishaq hold the same view. This hadith also shows that the Prophet, peace be upon him, offered funeral prayer at a grave when a funeral prayer had already been offered by his Companions for the deceased before her burial, for they could not bury her without a funeral prayer. From this hadith it is also obvious that praying for the dead (before the burial) was a common practice of the Companions, and was not limited only to the Prophet, peace be upon him.
Ibn Al-Qayyim said: “These proven traditions of the Prophet, peace be upon him, do not contradict the sound hadith that reports the statement of the Prophet, peace be upon him: ‘Do not sit by the graves, or offer prayer facing them.’ This is a sound hadith that bids us not to sit or pray at the graves. What is forbidden is to offer formal prayer (salah) facing a grave. Offering a funeral prayer at the grave is not forbidden, for funeral prayer does not have to be offered at any specific place. It is rather better offered outside a mosque than inside it. The funeral prayer at the grave is similar to offering it beside the coffin. In either case the prayer is offered for the deceased, and his body, whether it is in the coffin or in the grave, remains in the same position. Offering prayers other than funeral prayers are forbidden at graves, for there is a risk that this may tum these graveyards into mosques, against which the Prophet, peace be upon him, wamed us. He cursed those who tum graves into places of worship, saying: ‘Some evil people will be overtaken by the Day of Judgement, including those (evil people) who turn graves into mosques.’ This warning has no bearing on an act that the Prophet, peace be upon him, repeatedly performed. “