Mishkat al-Masabih 1125
وَعَنْ أَبِي هُرَيْرَةَ قَالَ: قَالَ رَسُولُ اللَّهِ صلى الله عَلَيْهِ وَسلم: «الْجِهَادُ وَاجِبٌ عَلَيْكُمْ مَعَ كُلِّ أَمِيرٍ بَرًّا كَانَ أَوْ فَاجِرًا وَإِنْ عَمِلَ الْكَبَائِرَ. وَالصَّلَاةٌ وَاجِبَةٌ عَلَيْكُمْ خَلْفَ كُلِّ مُسْلِمٍ بَرًّا كَانَ أَوْ فَاجِرًا وَإِنْ عَمِلَ الْكَبَائِرَ. وَالصَّلَاةٌ وَاجِبَةٌ عَلَى كُلِّ مُسْلِمٍ بَرًّا كَانَ أَوْ فَاجِرًا وَإِنْ عَمِلَ الْكَبَائِرَ» . رَوَاهُ أَبُو دَاوُد
From Abu Hurayrah, who said: The Messenger of Allah ﷺ said: "Jihad is obligatory upon you with every ruler, whether righteous or wicked, even if he commits major sins. Prayer is obligatory upon you behind every Muslim, whether righteous or wicked, even if he commits major sins. And [funeral] prayer is obligatory upon every Muslim, whether righteous or wicked, even if he committed major sins." Reported by Abu Dawud.