As mentioned previously, the battles that took place between the Messenger of Allah (saws) and the polytheists were for the purpose of repelling aggression, not for spreading of Islam. Believers were only permitted to fight when they were attacked:
أُذِنَ لِلَّذِينَ يُقَاتَلُونَ بِأَنَّهُمْ ظُلِمُوا ۚ وَإِنَّ اللَّهَ عَلَىٰ نَصْرِهِمْ لَقَدِيرٌ
(Permission [to fight] has been given to those who are being fought because they were wronged, and indeed Allah is capable of granting them victory) (Al-Hajj: 39)
This fighting is legitimate to defend oneself, wealth, honor, and homeland. It is a justified action according to the laws of both heaven and earth. As the battle of Badr was the first encounter, there would be captives, and there were not specific rules about them. Therefore, Allah (swt) clarified the ruling regarding them after the event took place:
(مَا كَانَ لِنَبِيٍّ أَن يَكُونَ لَهُ أَسْرَىٰ حَتَّىٰ يُثْخِنَ فِي الْأَرْضِ ۚ) (It is not for a prophet to have captives [of war] until he inflicts a massacre [upon Allah ‘s enemies] in the land,): Meaning, the believers must completely subdue the disbelievers in warfare, first, and then there can be an exchange of captives. Allowing the believers to possess a strength equivalent to that of the disbelievers, then the actions and reactions will be in accordance.
(تُرِيدُونَ عَرَضَ الدُّنْيَا وَاللَّهُ يُرِيدُ الْآخِرَةَ ۗ) (Some Muslims desire the commodities of this world, but Allah desires [for you] the Hereafter.): Meaning, do not seek the satisfaction of your worldly life’s pleasures; rather, Allah (swt) wants you to always strive for the Hereafter.