Quran 47:3-4 – “Those who reject Allah follow vanities, while those who believe follow the truth from their lord. Thus does Allah set forth form men their lessons by similitude. Therefore when you meet in battle those who disbelieve, then smite the necks until when you have overcome them, then make (them) prisoners,”
Chapter 47 of the Quran, was revealed at a time when Muslims were getting persecuted, killed by the pagan Quraish, 1400 years ago. The verse was specifically revealed straight after some of the Muslims immigrated to Madinah, fleeing persecution. (Maududi)
Let’s start reading few verses before to get a better understanding:
47:1 Those who disbelieve and avert [people] from the way of God – 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 God 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 God – never will He waste their deeds.
Reading verse 1 of chapter 47, there is many ways in which others are prevented in believing in Islam.
1. That a person is by force prevented in believing in Islam
2. That a person is persecuted and it is difficult for one to remain steadfast on his faith. Meaning, the person is persecuted, oppressed so much so that he/she will eventually leave his religion.
Reading verse 4 of chapter 47 of the Quran, the passage was revealed at a time in Madinah, when people were told to fight against tyranny and persecution, 1400 years ago. When we take a closer look towards the end of the verse it says, “those who are killed in the cause of Allah”, these same words are used in the following verses of the Quran,
Quran 2:190 Fight in the way of God those who fight you but do not transgress. Indeed. God does not like transgressors.
Quran 2:246 Have you not considered the assembly of the Children of Israel after [the time of] Moses when they said to a prophet of theirs, “Send to us a king, and we will fight in the way of God“? He said, “Would you perhaps refrain from fighting if fighting was prescribed for you?” They said, “And why should we not fight in the cause of God when we have been driven out from our homes and from our children?” But when fighting was prescribed for them, they turned away, except for a few of them. And God is Knowing of the wrongdoers.
Quran 4:75 And what is [the matter] with you that you fight not in the cause of Allah and [for] the oppressed among men, women, and children who say, “Our Lord, take us out of this city of oppressive people and appoint for us from Yourself a protector and appoint for us from Yourself a helper?”
So, reading the above verses it becomes evident that Q 47:4 does not encourage violence against the innocent. This shows, Quran 47:4 was revealed to fight in God’s cause in order to free people from oppression and tyranny, 1400 years ago.
4 Sc., ‘and on barring [others] from the path of God’ – thus connecting with verses 1 and laying down the fundamental condition which alone justifies physical warfare: namely, a defence of the Faith and of freedom (cf. in this connection 167 on 2:190). In other words, when ‘those who are bent on denying the truth’ try to deprive the Muslims of their social and political liberty and thus to make it impossible for them to live in accordance with the principles of their faith, a just war (Jihad) becomes allowable and, more than that, a duty. The whole of the above verse relates to war actually in progress (cf. note 168 on the first part of 2:191); and there is no doubt that it was revealed after 22:39-40, the earliest Qur’anic reference to physical warfare. 
 The Message of The Quran translated and explained by Muhammad Asad page 1067