Abu Huraira reported God’s Messenger as saying, “Jihad is a necessary duty for you along with any commander, pious or impious, even if he commits heinous sins; prayer is a necessary duty for you behind any Muslim, pious or impious, even if he commits heinous sins; and prayer is a necessary duty for every Muslim, pious or impious, even if he commits heinous sins.”
Abu Dawud transmitted it.