It is narrated from Sayyiduna Abu Hurayrah (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "Jihad is obligatory upon you along with every ruler, whether righteous or sinful; and prayer is obligatory upon you behind every Muslim, righteous or sinful, even if he commits major sins; and prayer is obligatory upon every Muslim, righteous or sinful, even if he commits major sins."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 5300