The soul is breathed into the child after 120 days in the womb, as the Prophet (peace be upon him) described the stages of creation — forty days as a nutfah, then a clot for the same period, then a lump for the same period, then an angel is sent who breathes the soul into it (Sahih al-Bukhari 3208; Sahih Muslim 2643). On that basis the position of the Hanbalis and many other scholars is that a child miscarried after four months is washed, shrouded, prayed over and buried like any Muslim, because al-Mughirah ibn Shuʿbah narrated that the Prophet said, "Prayer is offered over the miscarried child (siqt), and forgiveness and mercy are supplicated for his parents" (Sunan Abi Dawud 3180; Jamiʿ al-Tirmidhi 1031, who graded it hasan sahih). Before 120 days there is no janazah prayer; the remains are simply wrapped and buried respectfully. The Hanafis hold that the prayer is offered only if the child was born alive, and otherwise it is washed, wrapped and buried without the prayer — so a family following that practice should not be rebuked. In every case the child is buried with dignity, and many scholars recommend giving the child a name.
Q&A · Death & Afterlife
If a baby is stillborn or miscarried, is the funeral prayer offered for it?
Evidence — the daleel
On deen2u
Informational, not a personal fatwa. Consult a qualified scholar for rulings on your situation.