The Messenger of Allah ﷺ said, "The leader is but a shield, behind whom people fight and through whom they are protected. If he commands the fear of Allah and acts with justice, he will have reward for that. But if he commands otherwise, he will bear the burden of sin for it."
أخبرنا عمران بن بكار قال حدثنا علي بن عياش قال حدثنا شعيب قال حدثني أبو الزناد مما حدثه عبد الرحمن الأعرج مما ذكر أنه سمع
عن رسول الله ﷺ قال إنما الإمام جنة يقاتل من ورائه ويتقى به فإن أمر بتقوى الله وعدل فإن له بذلك أجرا وإن أمر بغيره فإن عليه وزرا
Bukhari narrated it in the Book of Jihad, chapter "Fighting behind the imam and seeking protection through him," hadith no. 2957, from the hadith of Shuayb bin Abu Hamza. Muslim narrated it in the Book of Leadership, chapter "The obligation of obeying rulers in matters other than sin, and its prohibition in sin," hadith no. 32/1835, from the hadith of Abu Zinad through the same chain. It is also found in Al-Kubra, hadith no. 7819.