All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and messenger.
If a woman and her baby both die, it is permissible to perform the funeral prayer on each separately. Also, it is better in the sight of Shaafi‘i and Hanafi jurists, since it will be, as stated by An-Nawawi more efficient and more hopeful to be accepted. But, it is also permissible to perform the funeral prayer on both of them together. This is better in the sight of Hanbali jurists because it helps to hasten the burial ceremonies of the dead and it agrees more with the conduct of the Companions .
In his Ahkaam Al-Janaa’iz, Al-Albaani says: “If there are several dead men and women, only one funeral prayer should be performed on them altogether, placing the deceased males, even if they are young, next to the Imaam and the deceased females next to the Qiblah. There are many Hadeeths in support of this. The first of which is narrated on the authority of Raafi' that 'Ibn ‘Umar performed the funeral prayer on nine of the deceased. He placed them all in one row, the males next to the Imaam and the females next to the Qiblah. On another occasion, the dead bodies of Umm Kulthoom bint ‘Ali ibn Abi Taalib, who is also the wife of ‘Umar ibn Al-Khattaab, along with a child of hers called Zayd were placed together and the Imaam was Sa‘eed ibn Al-‘Aas and, among the people praying were Ibn ‘Abbaas, Abu Hurayrah, Abu Sa‘eed and Abu Qataadah . The child was placed next to the Imaam, thereupon a man said: 'I disapprove of this.' I then looked at Ibn ‘Abbaas, Abu Hurayrah, Abu Sa‘eed and Abu Qataadah and asked them about it and they said it was an act of the Sunnah.' [An-Nasaa’i; Ibn Al-Jaarood, Ad-Daraqatni and Al-Bayhaqi] I said (i.e. Al-Albaani) the chain of narrators given by An-Nasaa’i and Ibn Al-Jaarood is authentic and meets the conditions stipulated by Al-Bukhari and Muslim." Then he (i.e. Al-Albaani) added: “But it is permissible to perform a funeral prayer on each of the deceased separately since it is the principle and the Messenger of Allaah, sallallaahu ‘alayhi wa sallam, did so with the martyrs of Uhud.”
On the other hand, it is impermissible to bury them together in the same grave unless there is a dire necessity – a ruling over which there is no dispute, whether the baby is a male or a female.
Allaah Knows best.