The funeral prayer may be offered for a child even if he was born dead.
➊ It is narrated from Mughira bin Shu’ba (may Allah be pleased with him) that the Messenger of Allah ﷺ said: والطفل يصلى عليه “The funeral prayer may be offered for a child.” And in one narration the words are: والسقط يصلي عليه “The funeral prayer may be offered for an incomplete child (miscarried fetus).”
➋ It is narrated from Aisha (may Allah be pleased with her) that a (deceased) child of the Ansar was brought to the Messenger of Allah ﷺ:
فصلي عليه
“He ﷺ offered the funeral prayer for him.”
(Albani, may Allah have mercy on him) These words are from Sunan al-Nasa’i, and its chain of narration is sahih (authentic). (He further explains that) it is clear that “incomplete” refers to a child whose four months have been completed and into whom the soul has been breathed, and who then dies. However, if he miscarries before this period in any case, the funeral prayer will not be offered for him, because he cannot be called a deceased person at all.
As is established in the hadith of Ibn Mas’ud (may Allah be pleased with him) that when a child reaches the age of four months in his mother’s womb:
وينفخ فيه الروح
“The soul is breathed into him.”
The narration in which these words occur:
إذا استهل السقط صلى عليه ووُرث
“When an incomplete child cries out, the funeral prayer will be offered for him and he will also be made an heir.” That narration is da’if (weak).