Overall meaning :
The Almighty states that it is not right for a prophet to take unbelieving combatants as prisoners of war until he has fought strenuously against them, become dominant in the land and vanquished them so that they will not be able to fight against the believers after that. Then, addressing the believers, He says: You desired the fleeting gains of this world by taking the defeated unbelievers prisoners after the Battle of Badr to release them in exchange for ransom, but Allah desires for you the reward of the life to come. Allah is All-Mighty, All-Wise. Had it not been for a decree from Allah that had already gone forth, you would have been sternly punished for the ransom you had taken from the Quraysh unbelievers.
Then He commands them to enjoy the good and lawful things which they have gained in war, and to fear Him by doing what He commands and avoiding what He forbids, stating that He is All-Forgiving, All-Merciful.
After that, He directs His Prophet, Muhammad, may Allah bless him and grant him peace, to inform the prisoners of war whom the Muslims released in exchange for ransom that if Allah finds goodness in their hearts and a sincere determination to accept Islam and be true believers, He will certainly grant them the best of this life and the hereafter, which will be far better than what has been taken from them, and He will forgive them their sins; surely Allah is All-Forgiving, All-Merciful.
But if they seek to betray you, He tells His prophet, may Allah bless him and grant him peace, they have already betrayed Allah, and He has made the believers triumph over them and take them captive. Allah is All-Knowing, All-Wise.