Well, Moses was first to do that.
17. "Now therefore kill every boy, and kill every woman who has been intimate with a man in bed. 18 But all the young women who have not experienced a man’s bed will be yours." (Numbers 31)
Mohammad and his followers did that routinely. That was part of the booty, 20% to Mohammad for God and the rest to the soldier as a gift of God - 'Maal-e-Ghanimat' (what your right hand holds). The slaves could be exchanged, as it happened in case of Juwayriyya bint al-Harith, who initially fell in the lot of a companion, Thabit b. Qays b. Al-Shammas, and Safiyya bint Huyeiy Ibn Akhtab who was intitially a slave of Dihya. Mohammad erred only in one case, that of Maria al-Qibtiyya, slave of his wife, Hafsa bint Umar. Maria was not held in the right hand of Mohammad. But Allah is great, he cleared the way for Mohammad: "O Prophet! why do you forbid (yourself) that which Allah has made lawful for you; you seek to please your wives; and Allah is Forgiving, Merciful. Allah indeed has sanctioned for you the expiation of your oaths and Allah is your Protector, and He is the Knowing, the Wise."
"Abu Sirma said to Abu Sa'id al Khadri (Allah he pleased with him): 0 Abu Sa'id, did you hear Allah's Messenger (may peace be upon him) mentioning al-'azl? He said: Yes, and added: We went out with Allah's Messenger (may peace be upon him) on the expedition to the Bi'l-Mustaliq and took captive some excellent Arab women; and we desired them, for we were suffering from the absence of our wives, (but at the same time) we also desired ransom for them. So we decided to have sexual intercourse with them but by observing 'azl' (Withdrawing the male sexual organ before emission of semen to avoid-conception). But we said: We are doing an act whereas Allah's Messenger is amongst us; why not ask him? So we asked Allah's Messenger (may peace be upon him), and he said: It does not matter if you do not do it, for every soul that is to be born up to the Day of Resurrection will be born." Sahih Muslim 3371.