Bismillah.
Narrated 'Amir:
Ibn Abbas (who was at that time a boy) said, "Allah's Apostle came to a grave and the people said, 'He or she was buried yesterday.' " Ibn Abbas added, "We aligned behind the Prophet and he led the funeral prayer of the deceased."
Prophet (SAW) prayed for the deceased person one day after he/she died. Question is, how long can a funeral prayer be delayed?
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).
[Taken from IslamQA]
Detailed answer here.
Wassalam.