The Messenger of Allah ﷺ said, "Goodness is tied to the forelocks of horses until the Day of Resurrection, namely reward and spoils of war."
قال رسول الله ﷺ: الخيل معقود في نواصيها الخير إلى يوم القيامة؛ الأجر والمغنم.
Bukhari narrated it in "Jihad and Expeditions" (2852), and Muslim in "Leadership" (1873:98), both through the route of Zakariya, from Amir Shaybi, from Urwa Bariqi, and he mentioned it.Imam Ahmad said, "The legal understanding of this hadith is that jihad is to be waged with every leader until the Day of Resurrection." Tirmidhi mentioned this from him following the hadith of Urwa Bariqi (1693). Bukhari titled a chapter in his Sahih, "Chapter, jihad continues with the righteous and the immoral," based on the saying of the Prophet ﷺ, "Goodness is tied to the forelocks of horses until the Day of Resurrection."The point drawn from this is that he mentioned the continuation of goodness in their forelocks until the Day of Resurrection, and explained it in terms of reward and spoils, and spoils combined with reward only come from horses through jihad. He did not restrict this to cases where the leader is just, which shows that there is no difference in attaining this merit between waging war with a just leader or an unjust one. Ibn Hajar said this in Fath al-Bari (6/56).It is narrated from Abu Hurairah in a marfu report, "Jihad is obligatory upon you with every commander, whether righteous or corrupt, and prayer is obligatory upon you behind every Muslim, whether righteous or corrupt even if he commits major sins, and prayer is obligatory upon every Muslim, whether righteous or corrupt even if he commits major sins."Abu Dawud narrated it (2533) from Ahmad bin Salih, who said, Ibn Wahb narrated to us, who said, Muawiya bin Salih narrated to me, from Ala bin Harith, from Makhul, from Abu Hurairah, and he mentioned it.Makhul did not hear from Abu Hurairah, as Abu Zura, Daraqutni, and others said.There are other hadiths with a similar meaning, but all of them are defective. See Ilal Mutanahiya (1/421–428), and Nasb Raya (2/27–28).