The Prophet ﷺ said, "The leader is but a shield, behind whom one fights and by whom one is protected. If he commands righteousness and justice, he will have a reward for that, but if he commands otherwise, he will bear the burden of it."
حدثنا عبد الملك بن عمرو حدثنا المغيرة عن أبي الزناد عن الأعرج
عن النبي ﷺ إنما الإمام جنة يقاتل من ورائه ويتقى به فإن أمر بتقوى وعدل فإن له بذلك أجرا وإن أمر بغير ذلك فإن عليه فيه وزرا
Its isnad is sahih. Bukhari related it, 4/60, in jihad, chapter on fighting behind the imam, as did Muslim, 3/1471, number 1841, Abu Dawud, 3/82, number 2757, and Nasai, 7/155, in pledge of allegiance, chapter on what is due to the imam and what is due from him.