We hold that obeying them is, in fact, an act of obedience to Allah—a binding duty so long as they do not command sin; we therefore pray that they be righteous and kept safe; and we follow the Sunnah and the Community, shunning eccentricity, discord, and division.
Allah says: “O you who believe, obey Allah, obey the Messenger, and those in authority among you” (al-Nisāʾ 4:59). In this verse Allah commands obedience to the Muslim rulers. As for an unbeliever, he has no authority over the Muslims: “Allah will never grant the unbelievers a way over the believers” (al-Nisāʾ 4:141). The phrase “those in authority among you” clearly refers to Muslims. Thus, their obedience is obligatory unless they order disobedience to Allah, for “no created being is to be obeyed if it entails disobedience to the Creator.” In such a case you do not obey him in that sin, yet this does not mean you revolt against him and withdraw obedience altogether; rather, you withhold obedience in that specific matter while continuing to obey him in everything else that is not sinful. The Prophet ﷺ said, “Obedience is only in what is right.” (1)
We ask Allah to return them to the truth and to rectify whatever errors they hold. We pray for their righteousness, for their righteousness means righteousness for the Muslims, their guidance means guidance for the Muslims, and the benefits they bring extend to others. When you pray for them, you are in reality praying for the Muslims.
This is a tremendous principle among the principles of Ahl al-Sunnah wa-l-Jamaʿah: to follow the Sunnah of the Prophet ﷺ, for he said, “Indeed, whoever among you lives long enough…"