The Medina Period and the Battles
As the idolaters' attacks grew in severity in Mecca, the Muslims migrated to the city of Yathrib (later known as Medina), where the climate was a great deal freer and friendlier, and set up their own administration there. Yet even after they established their own political structures, the attacks by the pagans of Mecca did not come to an end. The Quraysh followed the Muslims and persisted in violent attacks against them. But our Prophet (pbuh) and the Muslims around him never embarked on a battle against the idolaters.
No person, community or country in the world will fail to respond if they are attacked. They will always respond to the aggressor in "self defence" and at the very least, take defensive action. People who engage in self defence are invariably exonerated by the courts, and countries that act in self defence are exonerated under international law because they have been subjected to an unjust attack, and people's lives, families and loved ones, or countries' peoples, lands and honour, are endangered.
Our Prophet (pbuh) was given permission to engage in self defence for himself and his community in the following verses which were revealed after the migration to Medina:
Permission to fight is given to those who are fought against because they have been wronged – truly God has the power to come to their support – those who were expelled from their homes without any right, merely for saying, "Our Lord is God"… (Qur'an, 22:39-40)
With these verses, the Muslim community that had been unjustly forced into exile merely for saying "Our Lord is God" started to make preparations to defend themselves. As explicitly stated in the verse, a Muslim community "who are fought against because they have been wronged" are permitted to defend themselves; but they are not told to attack. Following this verse, Muslims began to defend themselves and fought back against the ferocious community that was attacking them. Verses concerning war and defence revealed after that contain descriptions regarding measures during the fighting taking place then. To put it another way, a special description is provided specific to the situation in that particular war. Therefore, all the verses about war in the Qur'an were specially revealed as referring to the particular attacks taking place at that time to enable us to see the difficult conditions of the time and the justice of our Prophet (pbuh).
The pagans of the time barbarically mistreated and tortured Muslims, in a way never seen before. Our Prophet (pbuh) was given permission in the verses to engage in self defence for himself and his community in the face of these attacks and wrongdoing.