If it is proven that the foetus has died in the mother’s womb, from the reports of trustworthy doctors, there is nothing wrong with aborting it, and there is no sin on the mother for that.
If the abortion is done before the pregnancy reached four months, then the foetus should not be named, no ‘aqeeqah should be done for it, it should not be washed and the funeral prayer should not be offered for it, and it may be buried anywhere, because before that stage (four months) the soul has not been breathed into it.
The scholars of the Standing Committee for Issuing Fatwas were asked:
I have a wife and Allah has blessed us with six children, praise be to Allah. After that my wife got pregnant five times, and miscarried at two or three months in the hospital. Each time she started to bleed and I took her to the hospital, where they put her to sleep (general anaesthetic) and “cleaned” her uterus (“d&c”). I do not know what they did with the foetus. Should I have buried it or not? If there is anything I should do about burying them, please advise me. Do I have to name them?
If the pregnancy did not reach four months, the foetus should not be washed, prayed for (funeral prayer), or named, and no ‘aqeeqah should be done for it, because the soul had not been breathed into it.
And Allah is the Source of strength. May Allah send blessings and peace upon our Prophet Muhammad and his family and Companions.
End quote from Fataawa al-Lajnah al-Daa’imah, 8/408.
For more information please see the answer to question no. 50106.
And Allah knows best.