All perfect praise be to Allaah, The Lord of the worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and messenger.
Scholars differed concerning offering the prayer on a fetus in the belly of its mother if four months passed before it was aborted. Should we pray over it or not? The most preponderant opinion is the permissibility of doing so.
This is based on the Hadeeth narrated on the authority of Al-Mughirah Ibn Shu‘bah that the Messenger of Allaah, sallallaahu ‘alayhi wa sallam, said: “… Prayer should be offered over the aborted and forgiveness and mercy should be supplicated for its parents.” [Ahmad and Abu Dawood].
As long as you did not offer the funeral prayer on your fetus, you may offer it now. Therefore, if you reside in the city where he was buried, you can offer the funeral prayer on his grave as the Prophet, sallallaahu ‘alayhi wa sallam, did so with regards to the woman who used to maintain the mosque. When she died, he, sallallaahu ‘alayhi wa sallam, asked his Companions to guide him to her grave and then the Messenger of Allaah, sallallaahu ‘alayhi wa sallam, offered the funeral prayer on her grave. [Al-Bukhari and Muslim].
However, if you are a resident outside this city, then you may offer the absentee funeral prayer like the Messenger of Allaah, sallallaahu ‘alayhi wa sallam, did on An-Najaashi, the king of Abyssinia. [Al-Bukhari and Muslim]
Allaah Knows best.