Certain verses of the Qur'an give the command to do battle (22:39). Here are a few points on this subject that we learn from our study of the Qur'an.
The first point is that to initiate aggression or armed confrontation is absolutely forbidden for Muslims. That is why the Qur'an clearly states: Fight in the cause of God those who fight against you, but do not transgress (2:190).
Islam allows only a defensive war. That is, when aggression is resorted to by others, Muslims may engage in war only in self-defence. The initiation of hostilities is not permitted for Muslims. Combat may be engaged in only when "they (the opponents) were the first to commence hostilities against you." (Qur'an, 9:13)
Furthermore, even in the face of aggression, Muslims are not immediately to wage a defensive war. Instead they are to employ all possible means to prevent a carnage from taking place. They are to resort to fighting only when it becomes totally unavoidable. All the battles that took place during the life of the Prophet provide practical examples of this principle. For instance, during the campaign of Ahzab, the Prophet attempted to avoid the battle by digging a trench, and thus successfully averted war. If, on the occasion of Hunain, the Prophet had to engage in battle, it was because it had become inevitable.
There was another kind of war, according to the Qur'an, which was temporarily desirable. That was the struggle to end religious persecution (fitna) (2:193).
In this verse 'fitna refers to that coercive system which reaches the extremes of religious persecution. Prevalent all over the world in ancient times, this system had effectively closed the doors to all kinds of spiritual and material progress for man. Therefore, God commanded His devotees to put an end to the kings' and emperors' reign of terror in order to usher in an age of freedom in which man might receive all kinds of spiritual and material benefits.
This task was undertaken internally within Arabia during the life of the Prophet of Islam. Afterwards, the Sassanid and Byzantine empires were dismantled by divine succour during the period of the rightly-¬guided caliphs. Consequently, the coercive political system ended at the international level, and thus began an age of intellectual freedom.
In this connection we find a very authentic tradition recorded in Sahih al-Bukhari. When, after the caliphate of Ali ibn Abi Talib, Abdullah ibn Zubayr and the Umayyads engaged themselves in political confrontation, Abdullah ibn Umar (son of the second Caliph) and the senior-most surviving companion of the Prophet kept himself aloof from this battle. A group of people came to him and, referring to the verse (2:193), which commanded the believers to do battle in order to put an end to persecution, asked him why he was not willing to join the battle, Abdullah ibn Umar replied that ‘fitna’ did not refer to their political confrontation, but referred rather to religious persecution, which they had already brought to an end. (Fathul Bari, 8/160).
This makes it clear that the war putting an end to persecution was a temporary war, of limited duration, which had already been concluded during the period of the rightly guided caliphs. Now justifying the waging of war by citing this verse is not at all acceptable. This verse will apply only if the same conditions prevail in the world once again.
Biographers of the Prophet have put the number of war campaigns at 80. When a reader goes through these biographies, he receives the impression that the Prophet of Islam during his 23-year prophetic period waged wars at least four times a year. But this impression is entirely baseless. The fact is that the Prophet of Islam in his entire prophetic period fought only three battles. All the other incidents, called ghazwa, or military expeditions, are in fact, examples of avoidance of battle, rather than of involvement in battle.
For instance, the incident of al-Ahzab has been called a battle in the books of seerah. Whereas in reality, on this occasion, 12,000 armed tribesmen of Arabia came to the border of Madinah in order to wage war, but the Prophet and his companions did not allow the battle to take place by digging a trench, which acted as a buffer between the Muslims and the aggressors. The same is the case with all those incidents, called ghazwa, or battles. Whenever the Prophet's opponents wanted to involve him in battle, the Prophet managed to defuse the situation by adopting one strategy or another.
There are three occasions when the Prophet entered the field of armed combat – at Badr, Uhud and Hunain. But as proven by events, fighting had become inevitable on all these occasions. The Prophet had no choice but to do battle with the aggressors. Furthermore, each of these military engagements lasted for only half a day, beginning at noon and ending by sunset. Therefore, it would not be wrong to say that the Prophet in his entire life took up arms only for one and a half days. That is to say, of the entire 23-year prophetic period, except for one and a half days, the Prophet observed the principle of non-violence.
While giving the command of battle to the Prophet and his companions, the Qur'an clearly states that it was the other party, which had commenced hostilities (9:13). This verse gives conclusive evidence that there is only defensive war in Islam. It is absolutely unlawful for the believers to wage an offensive war. The Islamic method is entirely based on the principle of non-violence. Islam does not allow for violence in any circumstance except that of unavoidable defence.
taken from: http://www.cpsglobal.org/content/command-war-islam