Fighting during the Sacred Months is prohibited, except in Self-Defense
Ibn `Abbas, Ad-Dahhak, As-Suddi, Qatadah, Miqsam, Ar-Rabi` bin Anas and `Ata said, "Allah's Messenger went for `Umrah on the sixth year of Hijrah. Then, the idolators prevented him from entering the Sacred House (the Ka`bah in Makkah) along with the Muslims who came with him. This incident occurred during the sacred month of Dhul-Qa`dah. The idolators agreed to allow them to enter the House the next year. Hence, the Prophet entered the House the following year, along with the Muslims who accompanied him, and Allah permitted him to avenge the idolators' treatment of him, when He said:
[الشَّهْرُ الْحَرَامُ بِالشَّهْرِ الْحَرَامِ وَالْحُرُمَـتُ قِصَاصٌ]
(The sacred month is for the sacred month, and for the prohibited things, there is the Law of equality (Qisas).)
Imam Ahmad recorded that Jabir bin `Abdullah said, "Allah's Messenger would not engage in warfare during the Sacred Month unless he was first attacked, then he would march forth. He would otherwise remain idle until the end of the Sacred Months.'' This Hadith has an authentic chain of narrators.
Hence, when the Prophet was told that `Uthman was killed (in Makkah) when he was camped at the area of Al-Hudaybiyyah, after he had sent `Uthman as his emissary to the polytheists, he accepted the pledge from his Companions under the tree to fight the polytheists. They were one thousand and four hundred then. When the Prophet was informed that `Uthman was not killed, he abandoned the fight and reverted to peace.
When the Prophet finished fighting with (the tribes of) Hawazin during the battle of Hunayn and Hawazin took refuge in (the city of) At-Ta'if, he laid siege to that city. Then, the (sacred) month of Dhul-Qa`dah started, while At-Ta'if was still under siege. The siege went on for the rest of the forty days (rather, from the day the battle of Hunayn started until the Prophet went back to Al-Madinah from Al-Ji`ranah, were forty days), as reported in the Two Sahihs and narrated by Anas. When the Companions suffered mounting casualties (during the siege), the Prophet ended the siege before conquering At-Ta'if. He then went back to Makkah, performed `Umrah from Al-Ji`ranah, where he divided the war booty of Hunayn. This `Umrah occurred during Dhul-Qa`dah of the eighth year of Al-Hijrah.
[فَمَنِ اعْتَدَى عَلَيْكُمْ فَاعْتَدُواْ عَلَيْهِ بِمِثْلِ مَا اعْتَدَى عَلَيْكُمْ]
(...whoever transgresses against you, you transgress likewise against him.) ordains justice even with the polytheists. Allah also said in another Ayah:
[وَإِنْ عَاقَبْتُمْ فَعَاقِبُواْ بِمِثْلِ مَا عُوقِبْتُمْ بِهِ]
(And if you punish, then punish them with the like of that with which you were afflicted.) (16:126)
[وَاتَّقُواْ اللَّهَ وَاعْلَمُواْ أَنَّ اللَّهَ مَعَ الْمُتَّقِينَ]
(And fear Allah, and know that Allah is with Al-Muttaqin (the pious)) (2:194) commands that Allah be obeyed and feared out of Taqwa. The Ayah informs us that Allah is with those who have Taqwa by His aid and support in this life and the Hereafter.
[وَأَنفِقُواْ فِى سَبِيلِ اللَّهِ وَلاَ تُلْقُواْ بِأَيْدِيكُمْ إِلَى التَّهْلُكَةِ وَأَحْسِنُواْ إِنَّ اللَّهَ يُحِبُّ الْمُحْسِنِينَ ]
(195. And spend in the cause of Allah and do not throw yourselves into destruction, and do good. Truly, Allah loves Al-Muhsinin (those who do good).)