Hanash bin al-Harith said: Sayyiduna Ali bin Abi Talib (may Allah be pleased with him) used to sacrifice one ram on behalf of the Messenger of Allah (peace and blessings be upon him) and one ram on his own behalf. We said: O Commander of the Believers, do you sacrifice on behalf of the Messenger of Allah (peace and blessings be upon him)? He said: "The Messenger of Allah (peace and blessings be upon him) ordered me to sacrifice on his behalf for ever, so I sacrifice on his behalf for ever."
Sharik bin Abdullah alone narrated it with this chain. If it is established, it indicates the permissibility of sacrificing on behalf of Muslims who have departed this world. As for sacrificing on behalf of an unborn child, al-Shafi'i said: No sacrifice is made on behalf of what is in the womb.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الضحايا / 19188