Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:8:67

It is not for a prophet to have captives ˹of war˺ until he inflicts a massacre ˹upon Allah 's enemies˺ in the land. Some Muslims desire the commodities of this world, but Allah desires ˹for you˺ the Hereafter. And Allah is Exalted in Might and Wise.  

The following was revealed when they ransomed those taken captive at Badr: It is not for any Prophet to have (read as an takūna lahu or an yakūna lahu) prisoners until he has made slaughter in the land, going all the way in fighting disbelievers. You, O believers, desire the transient things of this world, its ephemeral gains, by ransoming, while God desires, for you, the Hereafter, that is, its reward, through your killing them; and God is Mighty, Wise: this was abrogated by His words ˹and set them free˺ afterward either with grace or by ransom ˹Q. 47:4˺.
القرآن:٨:٦٧

مَا كَانَ لِنَبِيٍّ أَنْ يَكُونَ لَهُ أَسْرَىٰ حَتَّىٰ يُثْخِنَ فِي الْأَرْضِ ۚ تُرِيدُونَ عَرَضَ الدُّنْيَا وَاللَّهُ يُرِيدُ الْآخِرَةَ ۗ وَاللَّهُ عَزِيزٌ حَكِيمٌ  

ونزل لما أخذوا الفداء من أسرى بدر {ما كان لنبي أن تكون} بالتاء والياء {له أسرى حتى يثخن في الأرض} يبالغ في قتل الكفار {تريدون} أيها المؤمنون {عَرَض الدنيا} حطامها بأخذ الفداء {والله يريد} لكم {الآخرة} أي ثوابها بقتلهم {والله عزيز حكيم} وهذا منسوخ بقوله (فإما منّا بعد وإما فداءً).