Even those far removed from Jewish learning know that it is the mother who determines the Jewish status of a baby. Why this is so is not clearly spelled out. The simplest and most obvious reason would seem to be the fact that while we always know who the mother is, the identity of the father is less certain. The Talmudic assertion that "the majority of relations a woman has is with her husband" (Sotah 27a) is just that--a claim about the majority. However, a minority are not. One of the ethical dilemmas often facing hospital staff is what to do when they discover--through testing done before a medical procedure--that the husband is not the father of the child before them, a fact sometimes unknown to both husband and wife.
Despite these (hopefully) rare occurrences, Jewish law works on the assumption that the father of the baby of a married woman is the husband. But such an assumption can no longer hold if a woman were to remarry soon after the divorce or death of her first husband. It is for this reason that Jewish law prohibits a woman from marrying until 92 days have elapsed from the end of her previous marriage. Marry sooner, and there would be doubt if a baby born soon after the second marriage was a full-term baby of the first husband, or a premature baby of the second.
Not knowing the identity of the father is one (not good) thing; but of even greater concern is the case where the second marriage may, retroactively, turn out to be forbidden.
"If one marries his yevamah and we discover that she is pregnant; if the child is viable, he must divorce her and bring a sacrifice; if the fetus is not viable, he may remain married" (Yevamot 35b). The mitzvah of yibum is a unique, almost contradictory mitzvah. Marrying one's deceased brother's wife is a great mitzvah--provided the brother had no children. Yet if that same deceased brother did leave children--even children with a woman not his wife, even if he fathered a mamzer--then marrying his widow is amongst the most serious violations of Jewish law, one that carries the penalty of karet, excision.
When a man dies and leaves a pregnant wife, the yet-to-be born fetus is still the seed of the father. And if such a fetus survives thirty days, the woman is free to marry whomever she pleases, without the need for chalitzah; and the brother of the deceased is forbidden to marry her on the penalty of karet. If the brother marries his pregnant sister-in-law--deliberately or unknowingly--whether such is a grievous sin or the retroactive performance of a "mitzvah" will not be known for many months. Amazing!
While our rabbis forbade such a marriage, the Sages of the Mishnah would allow the marriage to continue if and when the woman either miscarries or gives birth to a baby who dies within thirty days, not such an uncommon occurrence in Mishnaic times. The Gemara (but interestingly, not the Mishnah) quotes the dissenting view of Rabbi Eliezer that, having violated rabbinic law by marrying a woman before ruling out the possibility of her pregnancy, they must divorce and may not remarry even if the baby does not survive.
When a man leaves a pregnant wife, eventually we will know if the brother may do yibum. More likely is the last case of the Mishnah, where we may never know the true status of the couple. Here, yibum is done soon after the death of the first husband, and the woman gives birth seven (or eight) months later. Is this the full-term baby of husband number one--in which case yibum is forbidden--or is the baby the premature baby of the second husband, in which case they are in fulfillment of the mitzvah of yibum? With no way to know with certainty who the father is, the Mishnah rules that the couple must divorce, and they must each bring an asham talui sacrifice.
While the status of the couple is in doubt, no such doubt exists regarding the child. Either he is a product of the first husband or the second. While this uncertainty requires the couple to divorce either way, the child is the product of a permissible relationship. As such, the Gemara (Yevamot 37a) notes, he can even become the kohen gadol.
 With the amazing developments in reproductive technology, it is no longer always certain who the mother is, as we have the ability to separate the biological and the gestational mother. Leading rabbinic authorities have not yet reached a consensus on who is the halachic mother--or shall we say, mothers.
 It is for this reason that Rav Herschel Schachter generally advised against paternity testing, as such may reveal that a child is a mamzer. Sometimes what we don't know can't hurt us.
 The Sages of the Talmud, in accordance with the scientific view of the times, were of the view that, while a seven-month baby might be viable, a baby born after eight months was not, something that--if it ever was true--is not true today.
 This sacrifice, literally a hanging sin, is brought when one is in doubt as to whether one has violated a Torah prohibition carrying the penalty of karet. If one subsequently finds out that such was indeed violated, he or she would be obligated to bring a korban chatat, a sin offering.
 The fact that we cannot identify the real father is is irrelevant. We know that his father, whoever he is, is a kohen; and that is all we need. One is meant to be "judged" on his own merits.