The gemara says that before beis din would carry out capital punishment on a pregnant woman, they would kill the fetus inside of her to prevent the nivul that would occur if they were to kill her first. The gemara concludes from this that if they would first kill her, she would die before the fetus. However, the gemara asks from a source that indicates that a fetus would always die prior to the woman carrying it. The gemara reconciles this by making a distinction between a woman who is murdered in which case she may die first, and a woman who dies naturally in which case the fetus will ALWAYS die first.
It is reported that this gemara was a strong indication for Rav Shlomo Zalman to reject brain stem death as being dead. Since a brain stem dead patient can carry and deliver (Cesarean) a child, it must not be considered dead because it would contradict the gemara's rule that the child will always die before the mother. The fact that the mother can be brain dead and deliver a healthy child indicates that brain death is still alive.
However, in the very next line the gemara says that shabbos may be violated to save the unborn fetus of a pregnant woman who died in childbirth. The implication is that although she died naturally, her fetus may still be living. Rashi comments that sometimes the mother will die before the fetus which creates a safeik pikuach nefesh that justifies the violating of shabbos to save the fetus. According to Rashi it seems that there cannot be a rule that a mother will always die before the child. This would certainly undermine Rav Shlomo Zalman's assumption because the fact that a viable child may be born from a brain dead patient would not prove that brain stem death is still considered living. In truth, Rashi's approach is quite difficult. Just as we are able to assume in the case of inheriting from the mother to bequeath to the father's relatives, that fetus perished before the mother based on the rationale of the gemara - איידי דוולד זוטרא חיותיה עיילה טיפה דמלאך המות ומחתך להו לסימנין, we should be able to rely on that assumption for shabbos as well. Yet, Rashi would seem to hold that we can make that assumption when dealing with monetary issues but it will not be overwhelming enough to prevent an attempt at saving the fetus on the chance that it outlived the mother.
The Shita Mi'kubetzes (15) reconciles the apparent contradiction with a smoother approach. The Shita explains that when a woman is carrying a child but hasn't yet gone into labor, any natural cause of death would affect her fetus before it affects her, therefore her fetus will die first. But, when she has already gone into labor and the fetus has gotten some degree of independence, it is possible and even likely that the fetus will be able to live even after the mother has died (therefore permitting the violation of shabbos to save the fetus). According to this approach the original rule remains strong that prior to labor, when a pregnant woman dies a natural death, her fetus will always die before she dies. Therefore, it is reasonable for Rav Shlomo Zalman to assume that if a brain dead woman can "live" on life support for weeks until her baby is born, it is an indication that she isn't truly dead because a dead woman cannot produce a live baby.
Many years ago, there was an experiment done in Israel led by Dr. Avrohom Steinberg (a proponent of brain stem death being halachic death) to disprove Rav Shlomo Zalman's source. The experiment involved decapitating a pregnant sheep while hooked up to a heart-lung machine, and then successfully delivering a live lamb. There is no debate that a decapitated person or animal is considered dead, yet the baby lamb was able to outlive the trauma of the mother's decapitation. What does this prove? Seemingly it would prove that the gemara's principal is outdated. In the time of the gemara the rule may have been true that a fetus cannot remain alive after it's mother has died, but with modern technology it is a possibility. Therefore, the gemara would not disprove the concept of brain stem death being halachic death.
The problem with this experiment (which i surprisingly couldn't find discussion about) is that the gemara itself differentiates between natural death and one who is killed. The gemara accepts that when one is killed, the fetus can outlive it's mother. It is only when the mother dies through natural causes that the fetus must die first. Therefore, the sheep experiment would concur to the gemara's principal that killing the mother would not kill the fetus, yet when the mother would become brain dead without the trauma of being murdered, it would still be a viable source that brain death is not halachic death. It is unclear to me what exactly this experiment was meant to prove. It seems that the experiment wasn't meant to technically undermine the proof from our gemara. Rather the experiment was just meant to show that the heart and lung can continue to work well after decapitation, proving that life cannot be determined by heart and lung functionality.