It is narrated from Sayyiduna Abdullah bin Abbas (may Allah be pleased with them both) concerning the saying of Allah Almighty: "It is not for a prophet to have captives until he has thoroughly subdued (the enemy) in the land" [Surah al-Anfal: 67], that this (ruling) was on the day of Badr, when the Muslims were few. When they became many and strong, Allah Almighty said: "Then either a favour afterwards or a ransom" [Surah Muhammad: 4]. So Allah gave the Prophet (peace and blessings be upon him) and the believers the choice concerning the captives: if they wish, they may kill them; if they wish, they may enslave them; and if they wish, they may take ransom for them.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب قسم الفيء والغنيمة / 12857