The Messenger of Allah ﷺ said, "Jihad is obligatory upon you alongside every leader, whether righteous or sinful. Prayer is obligatory upon you behind every Muslim, whether righteous or sinful, even if he commits major sins. And the funeral prayer is obligatory over every Muslim, whether righteous or sinful, even if he committed major sins."
حدثنا أحمد بن صالح حدثنا ابن وهب حدثني معاوية بن صالح عن العلاء بن الحارث عن مكحول
قال رسول الله ﷺ الجهاد واجب عليكم مع كل أمير برا كان أو فاجرا والصلاة واجبة عليكم خلف كل مسلم برا كان أو فاجرا وإن عمل الكبائر والصلاة واجبة على كل مسلم برا كان أو فاجرا وإن عمل الكبائر
[Its isnad is daif] mentioned earlier, no. 594. Bayhaqi (3/121) also narrated it from the hadith of Abu Dawud, through the same route.