This is one of the first verses revealed for fighting against the Quraysh who wronged and persecuted the believers for thirteen years. (Tafsir Ibn kathir, Tanwir al-Miqbas min Tafsir Ibn ‘Abbas, Asbab Al-Nuzul by Al-Wahidi and Ibn Al-Qayyim Al-Jawziyyah in Mukhtasar Zad Al-Ma’ad).
22:39 Permission [to fight] has been given to those who are being fought, because they were wronged. And indeed, Allah is competent to give them victory.
22:40 [They are] those who have been evicted from their homes without right – only because they say, “Our Lord is Allah.” And were it not that Allah checks the people, some by means of others, there would have been demolished monasteries, churches, synagogues, and mosques in which the name of Allah is much mentioned. And Allah will surely support those who support Him. Indeed, Allah is Powerful and Exalted in Might.
From the above verses we deduce the following facts:
(1) The Muslims were given permission to fight because others had been fighting them.
(2) This permission was given because the Muslims were “wronged” i.e., persecuted for over 13 years and continued even when the Muslims lived in Madinah.
(3) The Muslims were exiled out of their homes without any right only because they believed that God is One.
(4) And had it not been for God to give permission to fight against tyrants and persecutors, many monasteries, Churches, Synagogues and Mosques in which God’s name is proclaimed would have been destroyed.
“When the Prophet was expelled from Makkah, Abu Bakr said: ‘They have driven out their Prophet to their own doom.’ So Allah, Most High, revealed: ‘Permission (to fight) is given to those who are fought against, because they have been wronged; and surely, Allah is able to give them victory (22:39).’ So Abu Bakr said: ‘Then I knew that there would be fighting.’” (Jami` at-Tirmidhi Vol. 5, Book 44, Hadith 3171)
“When the Prophet was expelled from Makkah a man said: ‘They have driven out their Prophet’ so (the following) was revealed: “Permission (to fight) is given to those who are fought against, because they have been wronged; and surely, Allah is able to give them victory. Those who have been expelled from their homes unjustly (22:39).” [Those who were expelled were the Prophet and his Companions.] (Jami` at-Tirmidhi Vol. 5, Book 44, Hadith 3172)
Sayyid Abul Ala Maududi:
78 This (v. 39) is the first verse of the Qur’an in which permission to tight was given in the month of Zil-Hajj in the first year after Hijrah according to our research. Then the command to fight was given in vv. 190, 191, 193, 216 and 244 of Chapter II (Al-Baqarah) in Rajab or Sha`ban of A.H. 2.
79″…..and Allah is certainly able to help them”: this assurance was urgently needed by the persecuted Muslims whose fighting strength at that time was very meager, not even a thousand including all the migrants and the Muslims of al-Madinah. On the other hand, the fighting strength of the Quraish by themselves was much greater. Besides, they had all the other mushrik clans of Arabia at their back and were joined later by the Jews as well.
Therefore, this assurance was most opportune and the challenge to the disbelievers was very significant, for it meant to say that they were not fighting against a small number of the Muslims but against Allah. Therefore, “You are. welcome to fight if you dare”.
80 The mention of their expulsion from their homes in v. 40 is a clear proof that this portion of Surah al-Hajj was revealed at al-Madinah.
81 In order to have an idea of the severe persecution of the Muslims, a few instances of this are cited.
(1) Hadrat Suhaib Rumi was deprived of everything, when he was about to migrate to al-Madinah. When he reached there, he had nothing with him except the clothes he was wearing. Though he had earned all that through his own labors he was deprived of everything by the disbelievers of Makkah.
(2) When Hadrat Abu Salmah was about to leave Makkah with his wife and a suckling child, his in-laws forcibly separated his wife from him, and then the people of his own family tore away the child from them. Thus the poor woman had to pass one whole year in sorrow and grief. After a year, she secured the child somehow and journeyed from Makkah to al-Madinah with it all alone on a dangerous route.
(3) `Ayyash bin Rabi`ah was a half brother of Abu Jahl: When he migrated to al Madinah, he was followed by Abu Jahl and another brother of his, and they told him the lie: “Your mother has taken the oath that she will not move from the sun to the shade nor comb her hair until she should see you (`Ayyash) You should therefore go back with us to Makkah,’ show her your face and then come back”.
He was taken in by this trick. When they were journeying back the two brothers made him a prisoner, took him to Makkah with his hands and feet tied, and proclaimed, “O people of Makkah, this is how these lads should be treated and set right”. He remained in that state for a long time and was at last rescued by a brave Muslim.
82 Saumah (pl. Swami), Biyah and Salawat in the original Text are the places of worship of the monks who have left the world, the Christians and the Jews respectively. Salawat was Salauta in Aramaic, which might be the origin of the English words salute and salutation.
83 In this sentence, a Divine principle has been stated:
“Allah does not let a group of people or a community have authority for ever. Every now and then He repels one group by means of another”. If this had not been the case, the permanent dominator would have created chaos not only in the political and economic spheres, but would have encroached upon the places of worship as well. This “principle” has also been stated in v. 251 of Chapter II (Al-Baqarah). 
Tafsir al-Jalalayn (15/16th century commentary):
“Permission is granted to those who fight, namely, to the believers, to fight back — this was the first verse to be revealed regarding the struggle [in the way of God] (jihad), because they have been wronged, as a result of the wrong done to them by the disbelievers. And God is truly able to help them;
they are, those who were expelled from their homes without right, for their expulsion; they were expelled, only because they said, that is, because of their saying: ‘Our Lord is God’, alone: such a saying is ‘right’, and so then to be expelled for [saying] it is to be expelled without right. Were it not for God’s causing some people (ba‘dahum, ‘some’, substitutes for al-nasa, ‘people’) to drive back others, destruction would have befallen (read la-huddimat to emphasise a great number [of destructions]; or read la-hudimat)
The monasteries, (sawami‘) is for monks, and churches, (kana’is) are for Christians, and synagogues, (salawat) is the Hebrew term for Jewish houses of worship (kana’is), and mosques, (masajid) are for Muslims, in which, that is, in which mentioned places, God’s Name is mentioned greatly.
And with such destruction acts of worship cease. Assuredly God will help those who help Him, that is, [who] help His religion. God is truly Strong, overpowering His creation, Mighty, Invincible in terms of His dominion and power…” (Tafsir al-Jalalayn on Surah 22:39 – Online Source.
Tanwir al-Miqbas min Tafsir Ibn Abbas:
“(Sanction is given unto those who fight) sanction has been given to the believers to fight the disbelievers of Mecca (because they have been wronged) the disbelievers of Mecca wronged them; (and Allah is indeed Able to give them victory) Allah is able to give the believers victory over their enemies…” (Tanwir al-Miqbas min Tafsir Ibn Abbas on Surah 22:39 – Online Source)
Al-Wahidi (d. 1075 AD):
(Sanction is given unto those who fight because they have been wronged…) [22:39]. The commentators of the Qur’an said: “The idolaters from among the people of Mecca were in the habit of harming the Companions of the Messenger of Allah. These Companions used to come always either beaten or with their skulls bashed in.
They complained to the Messenger of Allah, Allah bless him and give him peace, about this situation and he persistently told them: ‘Be steadfast, for I have not been commanded to fight’. This continued until the Messenger of Allah, migrated, upon which Allah, exalted is He, revealed this verse”.
Ibn ‘Abbas said:“When the Messenger of Allah, was taken out of Mecca, Abu Bakr, said about him: ‘We are unto Allah, and unto Him we shall return; we shall surely perish’. Allah, exalted is He, then revealed (Sanction is given unto those who fight because they have been wronged; and Allah is indeed Able to give them victory). Abu Bakr said: ‘I knew at that point that there will be fighting’”. (Asbab Al-Nuzul on Surah 22:39 – Online Source)
Tafsir Ibn kathir (1301 – 1373 AD):
“Al-`Awfi reported that Ibn `Abbas said, “This was revealed about Muhammad and his Companions, when they were expelled from Makkah.” Mujahid, Ad-Dahhak and others among the Salaf, such as Ibn `Abbas, `Urwah bin Az-Zubayr, Zayd bin Aslam, Muqatil bin Hayan, Qatadah and others said, “This is the first Ayah which was revealed about Jihad.” Ibn Jarir recorded that Ibn `Abbas said,
“When the Prophet was driven out of Makkah, Abu Bakr said, `They have their Prophet. Truly, to Allah we belong and truly, to Him we shall return; surely they are doomed.”’ Ibn `Abbas said, “Then Allah revealed the words: (Permission (to fight) is given to those (believers) fought against, because they have been wronged; and surely, Allah is able to give them victory.)” Abu Bakr, may Allah be pleased with him, said,
“Then I knew that there would be fighting.” Imam Ahmad added: “Ibn `Abbas said, `This was the first Ayah to be revealed concerning fighting.”’ This was also recorded by At-Tirmidhi and An-Nasa’i in the Book of Tafsir of their Sunans. At-Tirmidhi said: “It is a Hasan Hadith.”
… the idolators went to extremes to persecute Muslims, to expel the Prophet and resolving to kill him; when they sent his Companions into exile here and there, so that some went to Ethiopia and others went to Al-Madinah; when they settled in Al-Madinah and the Messenger of Allah joined them there,
And they gathered around him and lent him their support, and they had a place where Islam prevailed, and a stronghold to which they could retreat; then Allah prescribed Jihad against the enemy,
And this was the first Ayah to be revealed for it. … (Permission (to fight) is given to those fought against, because they have been wronged; and surely, Allah is able to give them victory. Those who have been expelled from their homes unjustly) Al-`Awfi reported that Ibn `Abbas said;
“They were driven out of Makkah to Al-Madinah unjustly, i.e., Muhammad and his Companions.” (only because they said: “Our Lord is Allah.”) means, they had not done anything to their people or committed any wrongs against them, apart from the fact that they believed in the Oneness of Allah and they worshipped Him Alone, with no partner or associate. But for the idolators, this was the worst of sins, as Allah says:
(and have driven out the Messenger and yourselves because you believe in Allah, your Lord!) ﴿60:1﴾. Then Allah says:
(For had it not been that Allah checks one set of people by means of another,) meaning, were it not for the fact that He repels one people by means of another, and restrains the evil of people towards others by means of whatever circumstances He creates and decrees, the earth would have been corrupted and the strong would have destroyed the weak. …” (Tafsir Ibn Kathir on Surah 22:39 – Online Source)
Dr. Muhammad Asad:
57 Lit., “inasmuch as they have been wronged”. Connecting with the promise, in the preceding verse, that “God will ward off [all evil] from those who attain to faith”, the present verse enunciates the permission to fight physically in self-defence. All relevant Traditions (quoted, particular, by Tabari and Ibn Kathir) show that this is the earliest Qur’anic reference to the problem of war as such.
According to ‘Abd Allah ibn ‘Abbas, it was revealed immediately after the Prophet left Mecca for Medina, i.e., at the beginning of the year 1 H. The principle of war is self-defence – and only in self-defence – has been further elaborated in Al-Baqarah, which was revealed about a year later (see 2:190-193 and the corresponding notes).
58 Lit., “were it not that God repels some people by means of others” (cf. the identical phrase in the second paragraph of 2:251).
59 The implication is that the defence of religious freedom is the foremost cause for which arms may and, indeed, must – be taken up (see 2:193 and the corresponding note 170), or else, as stressed in the concluding clause of 2:251, “corruption would surely overwhelm the earth”. 
Malik Ghulam Farid
“1956. With this verse is introduced the subject of Jihad. The theme of sacrifice has formed a befitting prelude to this all-important subject. Before the permission to fight in self-defence was given to Muslims, they were apprised of the importance of sacrifice. The verse throws a flood of light on the Islamic conception of Jihad. Jihad, was the verse shows, is fighting in defence of Truth. But, whereas Islam allows no aggressive war, it regards the waging of it to defend one’s honour, country or Faith as an act of the highest virtue. Man is God’s noblest handiwork.
He is the acme of His creation, its aim and end. He is God’s vicegerent on earth and the king of His whole creation (2:31). This is the Islamic conception of man’s high place in the universe. It is, therefore, only natural that the religion which has raised man to such a high pedestal should also have attached very great importance and sanctity to human life. Of all things man’s life, according to the Qur’an, is most sacred and inviolable. It is a sacrilege to take it except under very rare circumstances which the Qur’an has specifically mentioned (5:33; 17:34).
But no less important, according to Islam, is freedom of conscience. It is man’s most precious heritage – perhaps more precious than life itself. The Qur’an, which has attached the greatest sanctity to man’s life, could not have failed to acknowledge and declare the sacredness and inviolability of this, his most precious possession. It is in defence of this most precious of their possessions that the Muslims were allowed to take up arms.
1957. According to consensus of scholarly opinion this is the first verse which gave Muslims the permission to take up arms in self-defence. It lays down principles according to which Muslims can wage a defensive war, and sets forth along with the following verses the reasons which led a handful of Muslims, without arms and other material means, to FIGHT IN SELF-DEFENCE AFTER THEY HAS SUFFERED AT MECCA CEASELESS PERSECUTION FOR YEARS AND HAS BEEN PURSUED WITH RELENTLESS HATRED TO MEDINA AND WERE HARASSED AND HARRIED THERE TOO. The first reason given in this verse is that they have been wronged.
1958. This verse gives the second reason. It is that Muslims were driven out from their hearths and homes without a just and legitimate cause; their only offence being that they believed in One God. For years the Muslims were persecuted at Mecca, then they were driven out from it and were not left in peace even in their exile at Medina.
Islam was threatened with complete extirpation by a combined attack by the Arabian tribes around Medina, among whom the influence of the Quraish, on account of their being the custodians of the Ka’bah, was very great. Madina itself was honeycombed with sedition and treachery.
The Jews, compact and united, were opposed to the Holy Prophet whose difficulties instead of lessening had greatly increased by Emigration. It was under these highly unfavourable circumstances that Muslims had to take up arms to save themselves, their Faith and the Holy Prophet from extermination.
If ever a people had a legitimate cause to fight, it were the Holy Prophet Muhammed and his companions, and yet the unconscionable critics of Islam have accused him of waging aggressive wars to impose his Faith on an unwilling people.
1959. After giving reasons why the Muslims were obliged to take up arms, the verse mentions the object and purpose of the wars of Islam. The object was never to deprive other people of their homes and possessions or to deprive them of national freedom … It was to fight in self-defence and to save Islam from extermination and to establish freedom of conscience and liberty of thought.
It was also to defend places of worship belonging to other religions – the churches, the synagogues, the temples, the cloisters, etc. (2:194; 2:257; 840 & 8:73). Thus the first and foremost object of the wars of Islam was and will always be to establish freedom of belief and worship and to fight in defence of country, honour and freedom against an unprovoked attack. …” 
Maulana Muhammad Ali:
“39a. According to authentic reports, this is the earliest permission given to the Muslims to fight. … The words in which the permission is granted show clearly that war was first made on the Muslims by their opponents; and secondly, that the Muslims had already suffered great oppression at the hands of their persecutors. The words of the next verse, those who are driven from their homes, may refer to the emigration to Abyssinia, or to the exodus to Madinah, which commenced soon after the ‘Aqabah allegiance was sworn.
40a. The religious freedom which was established by Islam thirteen hundred years ago has not yet been surpassed by the most civilized and tolerant of nations. It deserves to be noted that the lives of Muslims are to be sacrificed not only to stop their own persecution by their opponents and to save their own mosques, but to save churches, synagogues and cloisters as well — in fact, to establish perfect religious freedom.
The mosques, though they are the places where the name of Allåh is remembered most of all, come in for their share of protection even after the churches and the synagogues. Early Muslims closely followed these directions, and every commander of an army had express orders to respect all houses of worship, and even the cloisters of monks, along with their inmates.” 
 Sayyid Abul Ala Maududi – Tafhim al-Qur’an – The Meaning of the Qur’an
 The Message of The Quran translated and explained by Muhammad Asad, page 726
 The Holy Qur’an – Arabic Text With English Translation & Short Commentary By Malik Ghulam Farid, page 679 – 681
 The Holy Quran – Arabic Text with English Translation, Commentary and comprehensive Introduction [Year 2002 Edition] by Maulana Muhammad Ali, Page 675 – 676