Before us is Mishnah 2 in the fourth chapter of Maseches Yevamos, which deals with a yavam who married his yevamah and afterward it was discovered that she had been pregnant. The basic question is whether there was any obligation of yibum here at all, and what the status of the couple and of the child is.
"Hakones es yevimto v'nimtzeis me'uberes v'yaldah":
The case is a yavam who performed yibum with his yevamah, as he is obligated to do since his brother died without children, and afterward it became clear that she had been pregnant, and she gave birth. The Mishnah distinguishes between two situations:
"Bizman shehavalad shel kayama" - when the child is viable, meaning it survived thirty days, it turns out retroactively that she was the wife of a brother who has children, and the prohibition of ervah remains fully in place. Therefore "yotzi" - he must divorce her, "v'chayavin b'korban" - both of them must bring a chatas offering for having transgressed the kares prohibition of a brother's wife.
"V'im ein valad shel kayama" - when the child is not viable, it turns out that she was indeed obligated in yibum, and therefore he may keep her as his wife permanently.
The Gemara adds that in the second case he must live with her again with the intention of fulfilling the mitzvah of yibum, since relations that took place while she was pregnant - even though the pregnancy was not viable - do not carry the status of yibum, and therefore one must make sure that there be intent to fulfill the mitzvah.
"Safek ben tishah larishon, safek ben shivah la'acharon":
A child was born after the yibum, and it is not known whether it is a full nine month pregnancy from the first husband or a seven month pregnancy from the second husband. If it is from the first, then there was no obligation of yibum here at all, and their status is as explained above. Because of this doubt the Mishnah rules "yotzi" - he must divorce her, since perhaps this is a viable child from the first husband, and she was never permitted to enter into yibum.
"V'havalad kasher" - the child is not a mamzer. If it came from a nine month pregnancy, then it is from the first husband; and if it came from a seven month pregnancy, then it is from the second husband, who was obligated to perform yibum with her. Either way there is no blemish in the child itself.
"V'chayavin b'asham talui" - an asham talui is the offering brought when a person is in doubt whether he has become obligated in a chatas. Its function is to serve as protection from the punishments set for one who may have transgressed a kares prohibition, and that protection stands for him until it becomes clear whether he is in fact obligated in a chatas or not. In our case, where it is unclear whether they transgressed the prohibition of a brother's wife, both of them must bring an asham talui.
In summary: In this Mishnah we learned the law of one who married his yevamah and she was found to be pregnant: if the child is viable, it turns out retroactively that there was no obligation of yibum here, and therefore he must divorce her and both are obligated in a chatas; and if the child is not viable, the yibum was valid and he keeps her, provided that he lives with her again with the intention of fulfilling the mitzvah of yibum. In the case of a doubt whether the child is a nine month child from the first husband or a seven month child from the second, because of the doubt he must divorce her, the child is legitimate, and both are obligated in an asham talui.