كتاب الإمارة
33  
The Book on Government
(13)
Chapter: The obligation of staying with the Jama'ah (main body) of the muslims when Fitn (tribulations) appear, and in all circumstances. The prohibition of refusing to obey and on splitting away from the Jama'ah
(13)
باب الأَمْرِ بِلُزُومِ الْجَمَاعَةِ عِنْدَ ظُهُورِ الْفِتَنِ وَتَحْذِيرِ الدُّعَاةِ إِلَى الْكُفْرِ ‏‏
Sahih Muslim 1848 a

It has been narrated on the authority of Abu Huraira that the Messenger of Allah (ﷺ) said:

One who defected from obedience (to the Amir) and separated from the main body of the Muslims - if he died in that state-would die the death of one belonging to the days of Jahiliyya (i.e. would not die as a Muslim). One who fights under the banner of a people who are blind (to the cause for which they are fighting, i.e. do not know whether their cause is just or otherwise), who gets flared up with family pride, calls (people) to fight for their family honour, and supports his kith and kin (i.e. fights not for the cause of Allah but for the sake of this family or tribe) - if he is killed (in this fight), he dies as one belonging to the days of Jahiliyya. Whoso attacks my Ummah (indiscriminately) killing the righteous and the wicked of them, sparing not (even) those staunch in faith and fulfilling not his promise made with those who have been given a pledge of security - he has nothing to do with me and I have nothing to do with him.
حَدَّثَنَا شَيْبَانُ بْنُ فَرُّوخَ، حَدَّثَنَا جَرِيرٌ، - يَعْنِي ابْنَ حَازِمٍ - حَدَّثَنَا غَيْلاَنُ بْنُ، جَرِيرٍ عَنْ أَبِي قَيْسِ بْنِ رِيَاحٍ، عَنْ أَبِي هُرَيْرَةَ، عَنِ النَّبِيِّ صلى الله عليه وسلم أَنَّهُ قَالَ ‏ "‏ مَنْ خَرَجَ مِنَ الطَّاعَةِ وَفَارَقَ الْجَمَاعَةَ فَمَاتَ مَاتَ مِيتَةً جَاهِلِيَّةً وَمَنْ قَاتَلَ تَحْتَ رَايَةٍ عُمِّيَّةٍ يَغْضَبُ لِعَصَبَةٍ أَوْ يَدْعُو إِلَى عَصَبَةٍ أَوْ يَنْصُرُ عَصَبَةً فَقُتِلَ فَقِتْلَةٌ جَاهِلِيَّةٌ وَمَنْ خَرَجَ عَلَى أُمَّتِي يَضْرِبُ بَرَّهَا وَفَاجِرَهَا وَلاَ يَتَحَاشَ مِنْ مُؤْمِنِهَا وَلاَ يَفِي لِذِي عَهْدٍ عَهْدَهُ فَلَيْسَ مِنِّي وَلَسْتُ مِنْهُ ‏"‏ ‏.‏
Reference : Sahih Muslim 1848a
In-book reference : Book 33, Hadith 83
USC-MSA web (English) reference : Book 20, Hadith 4555
  (deprecated numbering scheme)