We used to sell mothers of children during the time of the Messenger of Allah ﷺ and Abu Bakr. When Umar came to power, he forbade their sale.
كنا نبيع أمهات الأولاد على عهد رسول الله ﷺ، وأبي بكر، فلما كان عمر نهي عن بيعهن.
Narrated by Abu Dawud (3954), Ibn Hibban (4324), Hakim (2/18-19), and Bayhaqi (10/347), all through chains going back to Hammad bin Salama, from Qays bin Saad, from Ata bin Abu Rabah, from Jabir, who related it. Its chain of transmission is sahih.Bayhaqi also narrated it with a sahih chain from Ibn Umar, that Umar bin Khattab said, "Any slave girl who bears a child from her master, he may not sell her, nor give her away, nor pass her on as inheritance. He may continue to enjoy her, but when he dies she becomes free."The majority of the scholars among the companions and the successors adopted the position of Umar bin Khattab, except for what has been related from Ali bin Abu Talib. He had initially agreed with Umar, but then his view changed, as Abdul-Razzaq related (13224), from Mamar, from Ayub, from Ibn Sirin, from Ubayda Salmani, who said, I heard Ali say, "My view and the view of Umar agreed regarding mothers of children, that they should not be sold." He said, "Then afterward I came to hold the view that they may be sold." Ubayda said, "So I said to him, 'Your view together with the view of Umar, held in unity, is dearer to me than your view alone, held amid division,'" or he said, "amid discord." He said, "Ali laughed at that."Khattabi held a different view, saying, "It is possible that this was permitted in the earliest period, and then the Prophet ﷺ forbade it shortly before his departure from this world, and Abu Bakr did not come to know of it, because the matter did not arise during his days, given how short his term was, and given how occupied he was with matters of religion, fighting the people of apostasy, and setting right the people who had strayed from the call to Islam. The matter then remained as it was during the time of Umar for a period, until Umar forbade it once word of it reached him from the Messenger of Allah ﷺ, and so the people gave it up."Shafii said, "She remains a slave in her legal status, except that it is not permissible for her master to sell her, nor to remove her from his possession by any means other than manumission, and she becomes free from the principal estate when he dies." He said, "This is simply following the precedent of Umar bin Khattab."I have already explained the rulings concerning mothers of children in detail in Minna Kubra (9/350-360), and I do not think it necessary to repeat them here for fear of excessive length.