After the conquest of Makkah, while the Muslims were busy with their lives in path of God, praying, fasting and doing charity work the Hawazin and Thaqif tribe assembled an army to attack the Muslims. With news reaching the Prophet (p) of their plans, Prophet Muhammed and his people prepared to engage them. This occasion of war was called the battle of Hunayn (as verse 25 for chapter 9 mentions). This verse (below) relates to this event.
“Indeed, the number of months with Allah is twelve [lunar] months in the register of Allah [from] the day He created the heavens and the earth; of these, four are sacred. That is the correct religion, so do not wrong yourselves during them. And fight against the disbelievers collectively as they fight against you collectively. And know that Allah is with the righteous [who fear Him].” Qur’an 9:36
9:36 – The number of months in the sight of God is twelve, and four of them are sacred. The fighting mentioned in this verse here, refers to the battle of Hunayn. Wherein Hawazin and Thaqif assembled an army to attack the Muslims. This verse commands the believers then, to fight ‘collectively’ as the idolaters fight the Muslims ‘collectively’. From the verse we gather that this was mentioned while there was a battle going on, 1400 years (Tafsir Ibn Kathir).
Tafseer Ibn Kathir (1301 – 1373 AD):
“(and fight against the idolators collectively), all of you, (as they fight against you collectively.), all of them,
(But know that Allah is with those who have Taqwa), and know that initiating battle during the Sacred Months is forbidden. Allah said in other Ayat,
(O you who believe! Violate not the sanctity of the symbols of Allah, nor of the sacred month.) ﴿5:2﴾,
(The Sacred Month is for the Sacred Month, and for the prohibited things, there is the law of equality (Qisas). Then whoever transgresses the prohibition against you, you transgress likewise against him) ﴿2:194﴾, and,
(Then when the Sacred Months have passed, kill the idolators…) ﴿9:5﴾. As for Allah’s statement, (And fight against the idolators collectively as they fight against you collectively), it includes permission for the believers to fight the idolators in the Sacred Month, if the idolators initiate hostilities therein. Allah said in other Ayat, (The Sacred Month is for the Sacred Month, and for the prohibited things, there is the law of equality (Qisas)) ﴿2:194﴾, and,
(And fight not with them at Al-Masjid Al-Haram, unless they (first) fight you there. But if they attack you, then kill them.) ﴿2:191﴾. As for the Messenger of Allah laying siege to At-Ta’if until the Sacred Month started, it was a continuation of the battle against Hawazin and their allies from Thaqif. They started the fighting and gathered their men for the purpose of conducting war. The Messenger of Allah marched to meet them and when they took refuge in At-Ta’if, the Prophet laid siege to them so that they descend from their forts, but they inflicted casualties on Muslims. The siege continued for about forty days, during which a Sacred Month began, and the siege continued for several days in that month. The Messenger broke the siege and went back (to Makkah). So fighting that carries over into it ﴿the Sacred Month﴾ is not the same as initiating warfare during it, Allah knows best. (Tafsir Ibn Kathir on Surah 9:36 – Online Source)
Classical scholar Ibn Humam Al-Hanafi (d. 1457 CE) commenting on Quran 9:36 states:
“في قوله تعالى: “وقاتلوا المشركين كافة كما يقاتلونكم كافة” فأفاد أن قتالنا المأمور به جزاء لقتالهم ومسبب عنه. وقال أيضاً : المقصود من القتال هو إخلاء العالم من الفساد
And fight the polytheists together, just as they fight you together”, so this is proof that fighting is simply a response to their fighting. And he also said: “The reason behind fighting is to stop the world from corruption.” (Fath Al-Qadeer, by Ibn Humam Al-Hanafi, volume 4, page 277-279)
Dr. Muhammad Asad:
“55 I.e., “just as all of them are, as it were, united against you in their rejection of the truth, be united against them in your readiness for self-sacrifice”. As regards the circumstances in which the Muslims are authorized to make war against unbelievers, see the earlier parts of this surah, and especially verses 12-13, as well as 2:190-194, where the general principles relating to war are laid down.” 
Maulana Muhammad Ali:
“36a. The allusion here is to the Arab practice of postponing the pilgrimage to a month other than that in which it fell, for which see the next verse. Whether the object was intercalation, in order to make the solar and lunar year tally, or whether a continuous cessation of war for a fourth part of the year was too long, is a disputed point; but such postponement was undoubtedly a great hardship for a majority of the people.
36b. Fighting was prohibited in the sacred months (2:217). Excepting this, the Muslims were told to fight with the idolaters as the idolaters fought with them, i.e. since all idolaters united in fighting with the Muslims, the latter, too, should unite in fighting with them.” 
Don’t forget to follow Discover The Truth on Facebook and Twitter. PLEASE help spread the word by sharing our articles on your favourite social networks. Thank You!
 The Message of The Quran translated and explained by Muhammad Asad, page 383
Click to access The_Message_of_The_Quran__by_Muhammad_Asad.pdf
 The Holy Quran Arabic Text with English Translation, Commentary and comprehensive Introduction [Year 2002 Edition] by Maulana Muhammad Ali, page 407 [Chapter: 9]