Yevamot 37 - Yibum with a pregnant widow
The Sages forbade performing either yibum or a chalitzah with a woman for three months after the death of her husband. Here is why. Imagine that one marries the wife of his late brother two months after the brother dies. Imagine also that she gives birth seven months after this. Now we have two possibilities. It could be that this child is the full-term baby of the deceased. In this case yibum was forbidden in the first place, they have transgressed and must bring a sacrifice, and he needs to divorce her, because one cannot live with the wife of this brother who died but left a child.
On the other hand, if it is his child, born after seven months of pregnancy (in the time of the Talmud, the majority of babies were born after nine months, but a minority of healthy babies were born after seven months). Now it transpires that he was correct in doing a yibum, and they can continue living together.
However, we cannot distinguish between the two cases: it may be a child of nine months, which means that the marriage is a transgression, or of seven months, in which case the marriage would be a mitzvah. Since they cannot resolve this uncertainty, he sill must divorce her, and they bring a special sacrifice prescribed for cases of such doubts. But the child is not a mamzer in either case: either it is a child of the late brother or of the alive one, and in both cases it is legitimate.
Art: Mother and Child by Cornelis C. Zwaan