What Happens to a Baby When a Pregnant Woman Dies
Question

Is it permissible to open the abdomen of a dead woman in order to extract a living fetus?
Praise be to Allah.Shaykh ‘Abd al-Rahman al-Sa’di, may Allah have mercy on him said: 
“When a pregnant woman dies, it is permissible to open the abdomen in order to extract a living fetus if there is an interest to be served by that and it will not cause a greater evil, and that is not regarded as mutilation. 
What our companions [i.e., the Hanbalis] said is well known. They said that if a pregnant woman dies and there is a living child in her womb , it is haram to open her abdomen, but some women (midwives) should try manually to bring out the fetus who it is hoped might live.
If that is not possible, then she should not be buried until the one who is in her womb has died too. If (the child) has been partially born and is alive, then a cut may be made in order to birth the rest of him. This is the view of the jurists, based on the view that this is mutilation by cutting, and the basic principle is that mutilating the deceased is haram, unless it serves a certain greater purpose, i.e., if the child has been partially born and is alive, then a cut may be made in order to birth the rest of him, because that is in the interests of the infant, and because not cutting in this case will lead to the negative consequence of the child dying, and the living should be given greater care than the dead. 
But in modern times, when the art of surgery has become more refined, cutting the abdomen or any other part of the body is not regarded as mutilation; they do it to the living with their consent and agreement for various kinds of treatment, and it is most likely that if the jurists had seen that, they would have ruled that it is permissible to cut the abdomen of the pregnant woman in order to extract her living fetus, especially if the pregnancy is full term and it is known or thought most likely that the fetus is alive. 
Another thing which points to it being permissible to cut the abdomen and extract the living fetus is the fact that if there is a conflict between pros and cons, then the greater good should be given precedence and the lesser evil may be committed. Sparing the abdomen from any cutting is good, but saving the child and keeping him alive is a greater good. Cutting the abdomen is bad, but leaving the living child to suffocate in her womb until he dies is a greater evil. So cutting becomes the lesser of two evils. Moreover, we say that in such cases, cutting is not regarded as mutilation or evil, so there is nothing to rule out extracting the fetus at all. 
And Allah knows best.” 
(Fatwa Al-Sa’di, 189)