Tafsir Ibn Kathir -> Surah Al-Baqarah -> Fighting in the Sacred Area is prohibited, except in Self-Defense

Allah said:

﴿وَلاَ تُقَـتِلُوهُمْ عِندَ الْمَسْجِدِ الْحَرَامِ﴾

(And fight not with them at Al-Masjid Al-Haram (the sanctuary at Makkah))

It is reported in the Two Sahihs that the Prophet said:

«إنَّ هَذَا الْبَلَدَ حَرَّمَهُ اللهُ يَوْمَ خَلَقَ السَّموَاتِ وَالْأَرْضَ، فَهُوَ حَرَامٌ بِحُرْمَةِ اللهِ إِلى يَوْمِ الْقِيَامَةِ، وَلَمْ يَحِلَّ لِي إِلَّا سَاعَةً مِنْ نَهَارٍ، وَإِنَّهَا سَاعَتِي هذِهِ حَرامٌ بحُرْمَةِ اللهِ إِلى يَوْمِ الْقِيامَةِ، لا يُعْضَدُ شَجَرُهُ، وَلَا يُخْتَلىَ خَلَاهُ، فَإِنْ أَحَدٌ تَرَخَّصَ بِقِتَالِ رَسُولِ اللهِصلى الله عليه وسلّم، فَقُولُوا: إنَّ اللهَ أَذِنَ لِرَسُولِهِ وَلَمْ يَأْذَنْ لَكُم»

(Allah has made this city a sanctuary since the day He created the heavens and the earth. So, it is a sanctuary by Allah's decree till the Day of Resurrection. Fighting in it was made legal for me only for an hour in the daytime. So, it (i.e., Makkah) is a sanctuary, by Allah's decree, from now on until the Day of Resurrection. Its trees should not be cut, and its grass should not be uprooted. If anyone mentions the fighting in it that occurred by Allah's Messenger, then say that Allah allowed His Messenger, but did not allow you.)

In this Hadith, Allah's Messenger mentions fighting the people of Makkah when he conquered it by force, leading to some deaths among the polytheists in the area of the Khandamah. This occurred after the Prophet proclaimed:

«مَنْ أَغْلَقَ بَابَهُ فهُوَ آمِنٌ،وَمَنْ دَخَلَ الْمَسْجِدَ فَهُو آمِنٌ، ومَنْ دَخَلَ دَارَ أَبِي سُفْيَانَ فَهُوَ آمِن»

(Whoever closed his door is safe. Whoever entered the (Sacred) Mosque is safe. Whoever entered the house of Abu Sufyan is also safe.)

Allah said:

﴿حَتَّى يُقَـتِلُوكُمْ فِيهِ فَإِن قَـتَلُوكُمْ فَاقْتُلُوهُمْ كَذَلِكَ جَزَآءُ الْكَـفِرِينَ﴾

(...unless they (first) fight you there. But if they attack you, then kill them. Such is the recompense of the disbelievers.)

Allah states: `Do not fight them in the area of the Sacred Mosque unless they start fighting you in it. In this case, you are allowed to fight them and kill them to stop their aggression.' Hence, Allah's Messenger took the pledge from his Companions under the tree (in the area of Al-Hudaybiyyah) to fight (the polytheists), after the tribes of Quraysh and their allies, Thaqif and other groups, collaborated against the Muslims (to stop them from entering Makkah to visit the Sacred House). Then, Allah stopped the fighting before it started between them and said:

﴿وَهُوَ الَّذِى كَفَّ أَيْدِيَهُمْ عَنكُمْ وَأَيْدِيَكُمْ عَنْهُم بِبَطْنِ مَكَّةَ مِن بَعْدِ أَنْ أَظْفَرَكُمْ عَلَيْهِمْ﴾

(And He it is Who has withheld their hands from you and your hands from them in the midst of Makkah, after He had made you victors over them.) (48:24) and:

﴿وَلَوْلاَ رِجَالٌ مُّؤْمِنُونَ وَنِسَآءٌ مُّؤْمِنَـتٌ لَّمْ تَعْلَمُوهُمْ أَن تَطَئُوهُمْ فَتُصِيبَكمْ مِّنْهُمْ مَّعَرَّةٌ بِغَيْرِ عِلْمٍ لِّيُدْخِلَ اللَّهُ فِى رَحْمَتِهِ مَن يَشَآءُ لَوْ تَزَيَّلُواْ لَعَذَّبْنَا الَّذِينَ كَفَرُواْ مِنْهُمْ عَذَاباً أَلِيماً﴾

(Had there not been believing men and believing women whom you did not know, that you may kill them and on whose account a sin would have been committed by you without (your) knowledge, that Allah might bring into His mercy whom He wills ـ if they (the believers and the disbelievers) had been apart, We verily, would have punished those of them who disbelieved with painful torment.) (48:25)

Allah's statement:

﴿فَإِنِ انتَهَوْاْ فَإِنَّ اللَّهَ غَفُورٌ رَّحِيمٌ ﴾

(But if they cease, then Allah is Oft-Forgiving, Most Merciful.) which means, `If they (polytheists) cease fighting you in the Sacred Area, and come to Islam and repent, then Allah will forgive them their sins, even if they had before killed Muslims in Allah's Sacred Area.' Indeed, Allah's forgiveness encompasses every sin, whatever its enormity, when the sinner repents it.