أُذِنَ لِلَّذِينَ يُقَٰتَلُونَ بِأَنَّهُمْ ظُلِمُوا۟ ۚ وَإِنَّ ٱللَّهَ عَلَىٰ نَصْرِهِمْ لَقَدِيرٌ ﴿٣٩﴾
Sanction is given unto those who fight because they have been wronged; and Allah is indeed Able to give them victory;
The Prophet ﷺ spent 13 years in Mecca enduring persecution without fighting. Fighting began only after he and his community had been driven out and attacked, and in the ten years in Medina, scholars estimate that all the battles together cost around a thousand lives or fewer on both sides.
The Meccans tortured and killed early Muslims, boycotted the clan of the Prophet ﷺ for three years and plotted to kill him. After the migration to Medina, the Quraysh marched against the Muslims at Badr, Uhud and the Trench, and the last two were fought at the edge of the city to defend it. Where he could, he preferred treaties, as in the Treaty of Hudaybiyyah, and the conquest of Mecca took place almost without bloodshed, with a general pardon.
Critics point to the battles against Jewish tribes of Medina, such as Banu Qurayzah, which broke treaties during the siege. Muslims respond that these were in the context of treason during wartime and that the judgment was by a leader of their own allies according to their own law. The Prophet's overall life is seen by Muslims as a model of mercy, as the Quran describes him.
أُذِنَ لِلَّذِينَ يُقَٰتَلُونَ بِأَنَّهُمْ ظُلِمُوا۟ ۚ وَإِنَّ ٱللَّهَ عَلَىٰ نَصْرِهِمْ لَقَدِيرٌ ﴿٣٩﴾
Sanction is given unto those who fight because they have been wronged; and Allah is indeed Able to give them victory;
وَمَآ أَرْسَلْنَٰكَ إِلَّا رَحْمَةًۭ لِّلْعَٰلَمِينَ ﴿١٠٧﴾
We sent thee not save as a mercy for the peoples.
وَقَٰتِلُوا۟ فِى سَبِيلِ ٱللَّهِ ٱلَّذِينَ يُقَٰتِلُونَكُمْ وَلَا تَعْتَدُوٓا۟ ۚ إِنَّ ٱللَّهَ لَا يُحِبُّ ٱلْمُعْتَدِينَ ﴿١٩٠﴾
Fight in the way of Allah against those who fight against you, but begin not hostilities. Lo! Allah loveth not aggressors.