If a woman dies with a foetus in her womb, and there is the hope that he will live if he is taken out without doing a Caesarian, then he has to be taken out. If it is not possible to take him out except by doing a Caesarian, it is permissible to do that so as to save his life. But if there is no hope that he will live, it is not permissible to do the Caesarian because there is no benefit in doing it; rather he should be buried with his mother without the operation.
Al-Nawawi (may Allah have mercy on him) said: If a woman dies with a living foetus inside her, our companions said that if there is the hope that he will live, her stomach may be cut so that he may be taken out, then she may be buried. But if there is no hope that he will live, there are three points of view, but the correct view is that her stomach should not be cut; rather it should be left until he (the foetus) dies, then she may be buried.
End quote from Rawdat al-Taalibeen, 2/143
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said: This is the correct view especially nowadays when taking out the foetus is not regarded as mutilation. If a woman dies with a moving foetus in her womb, the operation should be done straight away and the foetus taken out, and this is not mutilation at all.
End quote from Sharh al-Kaafi.
He also said:
If there is a need for surgery, there are four scenarios…
The fourth scenario is where the mother is dead and the foetus is alive. If there is no hope that he will live, then it is not permissible to do the operation. But if there is the hope that he will live, if he has partially emerged then the mother’s stomach may be cut so as to take out the rest of him. If he has not emerged at all, then our companions (may Allah have mercy on them) said that the mother's stomach should not be cut in order to take out the foetus, because this is mutilation. But the correct view is that the stomach should be cut if he cannot be taken out without doing so. This is the view favoured by Ibn Hubayrah who said in al-Insaaf that it is more correct. End quote from Majmoo‘ al-Fataawa, 11/333
And Allah knows best.