Praise be to Allah.
If the foetus comes out alive and its cry is heard, then it dies, it should be washed and the funeral prayer offered for it; there is no scholarly dispute concerning this. It says in al-Mughni: “The scholars are unanimously agreed that if it is known to have lived and its cry has been heard, the prayer should be offered for it. But if its cry is not heard, Imaam Ahmad (may Allaah have mercy on him) said: “If it has completed four months [gestation], then it should be washed and the funeral prayer offered. This is the view of Sa’eed ibn al-Musayyib, Ibn Seereen and Ishaaq. Ibn ‘Umar offered the funeral prayer for the son of his daughter who was born dead.” (al-Mughni, 2/328)
It says in Masaa’il al-Imaam Ahmad, which (contains reports that) were narrated by his son ‘Abd-Allaah: “I heard my father being asked about the newborn, when should the funeral prayer be offered for him? He said: if he was miscarried after four months [gestation], the funeral prayer should be offered for him. He was asked, should the funeral prayer be offered for him even if his cry was not heard? He said, Yes.” (Masaa’il al-Imaam Ahmad allati rawaahaa ibnuhu ‘Abd-Allaah, 2/482, mas’alah no. 673)
The author of al-Mughni explained the reason why the funeral prayer may be offered for one concerning whom there is doubt that he lived at all, “The prayer offered for him is a kind of du’aa’ for him and his parents … so there is no need to be certain and sure that he lived at all, unlike matters of inheritance.”
Undoubtedly this is a good understanding, because inheritance has to do with the rights of others, whereas a prayer has to do with the relationship between a person and his Lord.
With regard to a foetus of less than four months gestation, it should not be washed and the funeral prayer should not be offered for it, but it should be wrapped in a cloth and buried. That is because the soul is not breathed into it until after four moths of gestation; before that it is not a soul so the funeral prayer cannot be offered over it; it is like inanimate objects or blood.
The evidence for that is the words of the Prophet (peace and blessings of Allaah be upon him): “The miscarried foetus should be prayed over (the funeral prayer), and supplication for forgiveness and mercy for his parents should be offered.” (Narrated by Abu Dawood; classed as saheeh by al-Albaani in Saheeh al-Jaami’, 3525).
In the case of a miscarried foetus whose sex cannot be determined, it should be given a name which is suitable for both males and females, such as Salamah, Qutaadah, Sa’aadah, Hind, ‘Utbah or Hibbat-Allaah.