Because it is impossible for her to give birth to a viable child in less than six months, the child belongs to the first master, and the sale is invalid. This is because selling an umm walad is prohibited, and every prohibited sale is invalid. This is based on the view that selling ummahāt al-awlād is prohibited, though the matter is subject to scholarly disagreement. During the time of the Prophet, peace and blessings be upon him, Abu Bakr, may Allah be pleased with him, and the early part of Umar’s caliphate, may Allah be pleased with him, ummahāt al-awlād were sold. Then, when Umar saw that people had begun separating women from their children, he prohibited this (1), just as he did with the issue of triple divorce. Hence, some scholars say that if an umm walad bears a child to her master and the child dies, her master may sell her, since the harm for which Umar prohibited it—separating her from her child—has ceased. However, the established position of the school is that whenever a slave woman bears her master something in which the form of a human being is discernible, she becomes an umm walad: she is emancipated upon his death, and it is not lawful to sell her. Accordingly, if he sells her to someone and she gives birth to a child in less than six months, it becomes clear that she was sold while she was an umm walad, because she was carrying a child. Thus, the sale is invalid: the purchaser takes back his money and returns the slave woman to her master.
His statement, “he emancipates her or sells her”: the sale is invalid. But is the emancipation invalid or not? It is not invalid, because it has increased her good. Whereas she would previously have been emancipated only upon his death, she has now become free. This is why he did not say that the emancipation is invalid.