كتاب الإمارة
33  
The Book on Government
(18)
Chapter: It is recommended for the army to swear allegiance to the ruler when intending to fight, and an account of Bay'at Ar-Ridwan beneath the tree
(18)
باب اسْتِحْبَابِ مُبَايَعَةِ الإِمَامِ الْجَيْشَ عِنْدَ إِرَادَةِ الْقِتَالِ وَبَيَانِ بَيْعَةِ الرِّضْوَانِ تَحْتَ الشَّجَرَةِ
Sahih Muslim 1861

It has been narrated on the authority of Abdullah b. Zaid who said:

A person came to him and said: Here is Ibn Hanzala who is making people swear allegiance to him. He (, Abdullah) asked: To what effect? He replied: To the effect that they will die for him. 'Abdullah said: I will never swear allegiance to this effect after the Messenger of Allah (ﷺ).
وَحَدَّثَنَا إِسْحَاقُ بْنُ إِبْرَاهِيمَ، أَخْبَرَنَا الْمَخْزُومِيُّ، حَدَّثَنَا وُهَيْبٌ، حَدَّثَنَا عَمْرُو بْنُ، يَحْيَى عَنْ عَبَّادِ بْنِ تَمِيمٍ، عَنْ عَبْدِ اللَّهِ بْنِ زَيْدٍ، قَالَ أَتَاهُ آتٍ فَقَالَ هَذَاكَ ابْنُ حَنْظَلَةَ يُبَايِعُ النَّاسَ فَقَالَ عَلَى مَاذَا قَالَ عَلَى الْمَوْتِ قَالَ لاَ أُبَايِعُ عَلَى هَذَا أَحَدًا بَعْدَ رَسُولِ اللَّهِ صلى الله عليه وسلم ‏.‏
Reference : Sahih Muslim 1861
In-book reference : Book 33, Hadith 120
USC-MSA web (English) reference : Book 20, Hadith 4592
  (deprecated numbering scheme)