كتاب الإمارة
33  
The Book on Government
(42)
Chapter: One who fights so that the word of Allah will be supreme is fighting in the cause of Allah
(42)
باب مَنْ قَاتَلَ لِتَكُونَ كَلِمَةُ اللَّهِ هِيَ الْعُلْيَا فَهُوَ فِي سَبِيلِ اللَّهِ ‏‏
Sahih Muslim 1904 b

It has been narrated (through another chain of transmitters) on the authority of Abu Musa who said. The Messenger of Allah (ﷺ) was asked which of the men fights in the way of Allah:

(one who fights) for displaying his valour; (a man who) fights out of his family pride and (a man who) fights for the sake of show, who amongst these fights in the way of Allah? The Messenger of Allah (ﷺ) said: Who fights that the word of Allah be exalted fights in the way of Allah.
حَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ، وَابْنُ، نُمَيْرٍ وَإِسْحَاقُ بْنُ إِبْرَاهِيمَ وَمُحَمَّدُ بْنُ الْعَلاَءِ قَالَ إِسْحَاقُ أَخْبَرَنَا وَقَالَ الآخَرُونَ، حَدَّثَنَا أَبُو مُعَاوِيَةَ، عَنِ الأَعْمَشِ، عَنْ شَقِيقٍ، عَنْ أَبِي، مُوسَى قَالَ سُئِلَ رَسُولُ اللَّهِ صلى الله عليه وسلم عَنِ الرَّجُلِ يُقَاتِلُ شَجَاعَةً وَيُقَاتِلُ حَمِيَّةً وَيُقَاتِلُ رِيَاءً أَىُّ ذَلِكَ فِي سَبِيلِ اللَّهِ فَقَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏ "‏ مَنْ قَاتَلَ لِتَكُونَ كَلِمَةُ اللَّهِ هِيَ الْعُلْيَا فَهُوَ فِي سَبِيلِ اللَّهِ ‏"‏ ‏.‏
Reference : Sahih Muslim 1904b
In-book reference : Book 33, Hadith 215
USC-MSA web (English) reference : Book 20, Hadith 4685
  (deprecated numbering scheme)