Praise be to Allah.
It seems from your question that you feel that you let your grandmother down. If you were in the same city and were able to attend the funeral prayer and burial, why did you not do that? What kept you from being present for the best thing that you could do to honour your grandmother when she died, and offer the funeral prayer and make du’aa’ for her and pray for forgiveness for her?
Grandfathers and grandmothers must be honoured and treated kindly, just like parents.
It says in al-Mawsoo’ah al-Fiqhiyyah (16/133):
Grandfathers and grandmothers are like parents in terms of honour. End quote.
But you have an opportunity to make up for what you missed, in sha Allaah. You can go and offer the funeral prayer over her grave. Imam al-Shaafa’i and others are of the view that it is permissible to offer the funeral prayer over the grave of the deceased. The evidence for that is:
The report narrated by al-Bukhaari (458) and Muslim (956) that the Messenger (peace and blessings of Allaah be upon him) offered the funeral prayer for a woman at her grave. She used to clean the mosque, and the Sahaabah had buried her without informing the Messenger (peace and blessings of Allaah be upon him) of her death.
It was narrated from Ibn ‘Abbaas (may Allaah be pleased with him) that the Messenger of Allaah (peace and blessings of Allaah be upon him) passed by a grave where the burial had taken place at night and said: “When was this one buried?’ They said: Last night. He said: “Why didn’t you tell me?” They said: We buried him in the dark of night and we did not want to wake you up. He stood up and we stood in rows behind him. Ibn ‘Abbaas said: And I was among them, and he offered the funeral prayer for him. Narrated by al-Bukhaari (1321).
It was narrated from Yazeed ibn Thaabit (may Allaah be pleased with him) that they went out with the Messenger of Allaah (peace and blessings of Allaah be upon him) one day and he saw a new grave. He said: “What is this?” They said: It is So and so, the freed slave woman of Banu So and so – and the Messenger of Allaah (peace and blessings of Allaah be upon him) recognized her name – She died at noon when you were taking a nap, and we did not want to wake you up for her. The Messenger of Allaah (peace and blessings of Allaah be upon him) stood and the people formed rows behind him, and he said takbeer four times (i.e., offered the funeral prayer). Then he said: “No one should die when I am still among you without you telling me, for my prayer for him will be a mercy.” Narrated by al-Nasaa’i (2022); classed as hasan by Ibn ‘Abd al-Barr in al-Tamheed (6/271). Classed as saheeh by al-Albaani in Saheeh al-Nasaa’i.
Ibn Abi Shaybah narrated in al-Musannaf (3/239) a number of reports from the Sahaabah and Taabi’een who offered the funeral prayer over graves after the burial, including ‘Aa’ishah (may Allaah be pleased with her), who offered the funeral prayer at the grave of her brother ‘Abd al-Rahmaan; and Ibn ‘Umar who offered the funeral prayer at the grave of his brother ‘Aasim; and Sulaymaan ibn Rabee’ah and Ibn Sireen and others. This was also narrated by Ibn Hazm in al-Muhalla (3/366) from Anas, ‘Ali and Ibn Mas’ood (may Allaah be pleased with them all).
Some fuqaha’ did not allow offering the funeral prayer over graves at all, and some of them limited it to one month or three days, but there is no evidence for this restriction.
Ibn Hazm (may Allaah have mercy on him) said in al-Muhalla (3/366):
With regard to restricting the funeral prayer to within one month or three days, it is clearly wrong because it is restricting it with no evidence. End quote.
Shaykh Ibn ‘Uthaymeen (may Allaah have mercy on him) said in al-Sharh al-Mumti’ (5/436):
The correct view is that we may offer the funeral prayer over graves even after one month, but some of the scholars imposed an interesting restriction, and said: That is subject to the condition that the person who is buried died at a time when the one who is praying was able to pray.
For example: If a man died twenty years ago, and a man who is thirty years old goes out to pray for him, that is valid, because when he died the one who is praying was only ten years old, so he could have offered the prayer for the dead man.
Another example: If a man died thirty years ago, and a man who is twenty years old goes out to pray for him, that is not valid, because the one who is praying did not exist at the time when the man died, so he could not have prayed for him.
So it is not prescribed for us to offer the funeral prayer at the grave of the Prophet (peace and blessings of Allaah be upon him), and we do not know of anyone who said that it is prescribed to offer the funeral prayer at the grave of the Prophet (peace and blessings of Allaah be upon him) or at the graves of the Sahaabah, rather we should just stand and say du’aa’. End quote.
For more information please see al-Umm (1/425), al-Majmoo’ (5/208-210), al-Mughni (2/194-195), Badaa’i’ al-Sanaa’i’ (1/315) and al-Mawsoo’ah al-Fiqhiyyah (16/35).
Honouring parents or grandparents does not stop when their life ends, rather it continues after their death, and the greatest way in which a person can honour his parents is by making du’aa’ for them and praying for forgiveness for them.
It was narrated that Abu Usayd Maalik ibn Rabee’ah al-Saa’idi said: Whilst we were with the Messenger of Allaah (peace and blessings of Allaah be upon him), a man from Banu Salamah came to him and said: O Messenger of Allaah, is there anything left that I can do to honour my parents after they die? He said: “Yes. Pray for them, ask for forgiveness for them, carry out their last wishes, uphold the ties of kinship that you would not have were it not for them, and honour their friends.” Narrated by Abu Dawood (5142); classed as hasan by Ibn al-‘Arabi in ‘Aaridah al-Ahwadhi (4/307); classed as saheeh by Shaykh Ibn Baaz in Majmoo’ al-Fataawa (9/295).
The author of ‘Awn al-Ma’bood (14/36) said: “Pray for them” means making du’aa’, and it includes the funeral prayer. This was the view of al-Qaari’. And in Fath al-Wudood it says: What is meant is praying for mercy for them. End quote.
And Allaah knows best.