Al-Kāfi - Volume 3 > A Woman Dies with Baby Moving Inside (The following chapters are best explained by fatwa, please consult fatwa.)
Hadith #2

2ـ عِدَّةٌ مِنْ أَصْحَابِنَا عَنْ أَحْمَدَ بْنِ مُحَمَّدِ بْنِ خَالِدٍ عَنْ وَهْبِ بْنِ وَهْبٍ عَنْ أَبِي عَبْدِ الله (عَلَيْهِ الْسَّلام) قَالَ قَالَ أَمِيرُ الْمُؤْمِنِينَ (عَلَيْهِ الْسَّلام) إِذَا مَاتَتِ الْمَرْأَةُ وَفِي بَطْنِهَا وَلَدٌ يَتَحَرَّكُ فَيُتَخَوَّفُ عَلَيْهِ فَشُقَّ بَطْنُهَا وَأُخْرِجَ الْوَلَدُ وَقَالَ فِي الْمَرْأَةِ يَمُوتُ وَلَدُهَا فِي بَطْنِهَا فَيُتَخَوَّفُ عَلَيْهَا قَالَ لاَ بَأْسَ أَنْ يُدْخِلَ الرَّجُلُ يَدَهُ فَيُقَطِّعَهُ وَيُخْرِجَهُ إِذَا لَمْ تَرْفُقْ بِهِ النِّسَاءُ.

2. A number of our people have narrated from Ahmad ibn Muhammad ibn Khalid from Wahab ibn Wahab who has said the following: “Abu ‘Abd Allah, ‘Alayhi al-Salam, has said that ’Amir al-Mu’minin, ‘Alayhi al-Salam, has said, ‘If a woman dies with the child moving in her womb whose life is in danger, her belly is opened and the child is taken out.’ About a woman whose child dies in her womb and her life is in danger, he (the Imam) said, ‘It is permissible for a man to enter his hand inside, cut it (the dead body) to take it out if there is no woman around.”