Commentators of the Quran are in agreement that chapter 47 was revealed in Madinah. These verses were revealed concerning the battle of Badr (Tanwir al-Miqbas min Tafsir Ibn Abbas, Tafsir Ibn Kathir and Mawdudi). This battle took place as a consequence of the aggression and hostilities of the Quraysh prior to Badr incident. The Muslims had no choice left but to retaliate against them, 1400 years ago.
For more information on this event, please click on the following article: “Review Of The Battle Of Badr”
47:1 Those who disbelieve and avert [people] from the way of Allah – He will waste their deeds.
47:2 And those who believe and do righteous deeds and believe in what has been sent down upon Muhammad – and it is the truth from their Lord – He will remove from them their misdeeds and amend their condition.
47:3 That is because those who disbelieve follow falsehood, and those who believe follow the truth from their Lord. Thus does Allah present to the people their comparisons.
47:4 So when you meet those who disbelieve [in battle], strike [their] necks until, when you have inflicted slaughter upon them, then secure their bonds, and either [confer] favor afterwards or ransom [them] until the war lays down its burdens. That [is the command].
And if Allah had willed, He could have taken vengeance upon them [Himself], but [He ordered armed struggle] to test some of you by means of others. And those who are killed in the cause of Allah – never will He waste their deeds.
47:1 – In this verse were are told that the disbelievers in the life-time of Prophet Muhammed (p) used to prevent people from believing in the message of Islam. There are many ways in which a person is barred from believing in Islam.
(1) A person is by force prevented in believing in the religion.
(2) That the person is persecuted so much so that it is difficult for one to remain steadfast on his religion. Meaning, that the individual is so oppressed he/she will eventually leave his religion (Tafsir al-Jalalayn).
47:2 – Those who believe in the message of Islam and do good deeds, God will remove their past sins and reward them what is due to them.
47:4 – The whole present verses (47:1-4) relates to war that was in progress in the life-time of Muhammed (p). The striking of necks refers in the battle already in place, 1400 years ago. The barring of others from God, connecting this verse (47:4) lays down the fundamental principle that alone justifies war, namely, fighting so man is free to worship what he wills.
Later in the verse it lays down what to do with those prisoners of war, once the war ends and the conflict has ceased. There are two options, (1) to free them graciously or (2) free them for a ransom that is acquired from them. Or exchange the captive for a Muslim prisoner.
Malik Ghulam Farid:
“2737. Works of disbelievers are rendered vain in that their efforts to arrest the progress of Islam produce no results.
2738. Athkhana fil Ardi means, he caused much slaughter in the land.
2739. The verse, in a nutshell, lays down some important rules about the ethics of war and its conduct and incidentally deals a deathblow of their faith, honour, lives or property, Muslims are enjoined to fight bravely and relentless (8:13-17).
(b) When war is once started, it should continue till peace is established and freedom of conscience secured (8:40).
(c) Prisoners are to be taken from the enemy only after regular and pitched battle has been fought, and the enemy is decidedly and positively beaten. Thus regular war is declared to be the only reason for taking prisoners; for no other reason free men can be deprived of their liberty.
(d) When war is over, prisoners should be released, either as an act of favour, or on taking ransom from them or by negotiating mutual exchange. They should not be held permanently in captivity or treated as slaves. The Holy Prophet set at liberty about a hundred families of Bani Mustaliq and several thousand prisoners of Hawazin after both these tribes had been decisively beaten in battle.
After the Battle of Badr ransom was accepted from the prisoners, and those who could not pay their ransom in money but were literate, were required to teach reading and writing to Muslims. The verse thus has struck very effectively at the roots of slavery, abolishing it completely and for ever.” 
Maulana Muhammad Ali:
“1a. A˙alla-hu is synonymous with ahlaka-hi or a˙a‘a-hu (T, LL), the first meaning he destroyed him or caused him to perish, and the second he wasted it or made it ineffective. The significance is that their endeavours to uproot Truth will be brought to naught. This chapter was revealed at a time when the enemies of Islam were at the height of their power, and had apparently uprooted Islam from Makkah, and were preparing to give it a death-blow at Madinah.
2a. This is another prophecy, a counterpart of the one contained in the previous verse.
The Muslims, whose condition, it is announced here, will be bettered, were in a most helpless condition at the time. The majority of them had just fled from their homes, almost penniless, to save their lives and to settle down at Madinah where, however, they were not left alone, the enemy being determined to crush them by force.
3a. Amthal is the plural of mathal, which means a description, condition, state or case, or a description by way of comparison, i.e., a parable (LL). V. 1 tells us of the condition of those who tried to uproot Truth, stating that their endeavours will be brought to naught, while v. 2 speaks of those who accept the Truth and states that their material as well as moral condition will be bettered. These are the conditions or descriptions referred to in v. 3.
4a. The word athkhana occurring in this passage has been fully explained in 8:67a. This passage mentions the only case in which prisoners of war can be taken, and thus condemns the practice of slavery, according to which men could be seized anywhere and sold into slavery. Here we are told that prisoners of war can only be taken after meeting an enemy in regular battle, and even in that case they must be set free, either as a favour or after taking ransom.
It was the former of these alternatives that the Holy Prophet adopted in most cases; for instance, in the case of the prisoners of the Banu Mustaliq, in which a hundred families were set at liberty, and in the case of Hawazin, in which fully six thousand prisoners of war were released merely as an act of favour.
Only in the case of the seventy prisoners taken at Badr is there mention of redemption having been taken, but this was when Islam was very weak and the powerful enemy was determined to crush it.
4b. Intasara min-hu signifies he exacted retribution from him (LA), or he exacted his due completely from him (T-LL). The meaning is that, if Allah had pleased, He could have punished the enemies of Islam otherwise than by war, but as He means to punish them by the hands of the Muslims, therefore battles must be fought.” 
Sayyid Abul Ala Maududi:
“1 ‘Those who disbelieved’: Those who refused to accept the teachings and guidance presented ‘by Muhammad (upon whom be Allah’s peace and blessings).
2 The verb sadd (from which saddu of the original is derived) is used both as a transitive and as an intransitive verb in Arabic. Therefore, the sentence would mean “they themselves refrained from adopting Allah’s Way” as well as they prevented others from adopting this way.”
There are several ways of preventing others from adopting Allah’s Way:
(1) That one should forcibly prevent another from believing;
(2) that one should so persecute the believers that it should become difficult for them to remain steadfast on the Faith and for others to embrace the Faith in view of the dreadful conditions…
6 This also has two meanings:
(1) That Allah changed their previous condition and put them on the right path and improved and bettered their lives for them; and
(2) that Allah has taken them out of the condition of weakness and helplessness and oppression in which they were placed till then; now He has created for them such conditions in which instead of being persecuted they will defend themselves against the oppressors; instead of living as subjects, they will now live and order their lives as free people, and will have the upper hand instead of being subdued and suppressed. …
The words of verse 20 below testify that this Surah was sent down at a time when the command for fighting had already been given in Surah AI-Hajj: 39 and AI-Baqarah: 190, and the hypocrites of Madinah and the people of the weak faith had been so upset that it seemed as if they were actually facing death.
Besides, vv. 67-69 of the Surah AI-Anfal also testify that this verse had been sent down before the Battle of Badr. There it has been said: “lt does not behove a Prophet to have captives until he has crushed down the enemies in the land.
You desire the gains of this world, but Allah desires the Hereafter, and Allah is All-Powerful, All-Wise. Had not a decree already been issued by Allah, you would have incurred a severe chastisement in consequence of what you have done. So eat of what you have taken as spoils because it is lawful and pure.
” A careful study of this passage, especially of its italicized portions, shows that what had displeased Allah on this occasion was that before crushing down the enemy completely in the Battle of Badr, the Muslims had started taking the enemy soldiers as captives, whereas the instruction given them in Surah Muhammad before the actual fighting was this:
“When you have crushed them completely, then bind the captives tight. ” However, as the Muslims had been permitted, among other things in Surah Muhammad, to accept ransom from the prisoners, Allah declared the money taken from the captives of Badr as lawful and did not punish them for that.
The words “Had not the decree already been issued by Allah.” are clearly pointing to the fact that the command for permission to accept ransom had already been given in the Qur’an before this event, and obviously, there is no other verse in the Qur’an beside this verse of Surah Muhammad, which contains this command.
Therefore, it will have to be admitted that this verse had been sent down before the above-cited verse of the Surah AI-Anfal. (For explanation, see E. N 49 on AI-Anfal). This is the first verse of the Qur’an in which preliminary instructions have been given about the laws of war.
Below is given a resume of the injunctions that are derived from this verse and the Holy Prophet’s and his Companions’ practice according to it and the juristic inferences as based on this verse and the Sunnah:
(1) The real aim of the Muslim army in war is to break the fighting power of the enemy till it is crushed and the war lays down its arms. Under no circumstances, should the Muslim’s lose sight of this aim and start taking the enemy soldiers as captives.
Captives should be taken after the enemy has been completely crushed and its numbers thinned down. The Arabs have been so instructed at the outset lest in the greed for ransom and taking slaves they should forget and overlook the real aim of the war.
(2) About the prisoners taken in war it has been said: “You have the option whether you show them favor or accept ransom from them. ” This gives the general law that the prisoners of war should not be put to death. Hadrat `Abdullah bin Umar, Hasan Basri, Ata’ and Hammad bin Abi Sulaiman favour this view, which is quite valid. They say that a man can be killed only during the war.
When the war is over and one has been made a prisoner, it is not lawful to kill him, Ibn Jarir and Abu Bakr al-Jassas have related that Hajjaj; bin Yusuf handed over one of the prisoners of war to Hadrat Abdullah bin Umar and commanded him to put him to death. He refused to obey and cited this verse and said:
“We are not allowed to kill a man when he is a prisoner.” Imam Muhammad in As-SiyaT al-Kabir also has related that Abdullah bin ‘Amir had commanded Hadrat `Abdullah bin `Umar to kill a prisoner of war, and he had refused to obey the command for this reason.
(3) But since in this verse it has neither been clearly forbidden to kill the prisoner the -Holy Prophet understood this intention of Allah’s Command, and also acted accordingly, that if there was a special reason for which the ruler of an Islamic government regarded it as necessary to kill a particular prisoner (or prisoners), he could do so. This is not the general law, but an exception to it, which would be applied only when necessary.
Thus, the Holy Prophet put to death only `Uqbah bin Abi Mu’ait and Nadr bin al-Harith from among the 70 prisoners taken at Badr, and only the poet Abu `Azzah from the prisoners taken at Uhud. From among the prisoners taken at Khaiber only Kinanah bin Abi al-Huqaiq was put to death because of his violating the agreement.
At the conquest of Makkah, the Holy Prophet commanded in respect of only a few particular persons from among all the inhabitants of Makkah that any one of them who was captured should be put to death. Apart from these exceptions, the Holy Prophet never killed prisoners of war, and the same also continued to be the practice of the righteous Caliphs. During their times also killing of prisoners of war was rare, which was resorted to only for a special reason.
Hadrat Umar bin Abdul `Aziz also during his caliphate put to death only one prisoner of war for the reason that he had persecuted the Muslims very cruelly. On this very basis the majority of the jurists have held the view that the Islamic government can put a prisoner to death if necessary. But it is for the government to take such a decision; every soldier is not permitted to kill any prisoner he likes. …” 
 The Holy Qur’an – Arabic Text With English Translation & Short Commentary By Malik Ghulam Farid,
Page 1019 – 1020
 The Holy Quran Arabic Text with English Translation, Commentary and comprehensive Introduction by Maulana Muhammad Ali, Page 987 – 988
 Sayyid Abul Ala Maududi – Tafhim al-Qur’an – The Meaning of the Qur’an http://www.englishtafsir.com/Quran/47/index.html#sdfootnote1sym