The Messenger of Allah ﷺ said, "There is no envy except in two cases. A man whom Allah has given wealth and empowered him to spend it in the cause of truth, and another whom Allah has given wisdom by which he judges and which he teaches to others."
قال رسول الله ﷺ: لا حسد إلا في اثنتين: رجل آتاه الله مالا، فسلطه على هلكته في الحق، وآخر آتاه الله حكمة فهو يقضي بها ويعلمها.
Bukhari narrated it in Chapters on Judgments (7141), and Muslim narrated it in Prayer of Travelers and its Shortening (816), both through the route of Ismail, from Qays, from Abdullah Ibn Masud, who related it.Hafiz said, "This hadith encourages taking on the position of judgeship for one who fulfills its conditions, has the strength to carry out what is right, and finds people to assist him, because it involves enjoining what is good, supporting the wronged, delivering what is due to those entitled to it, restraining the hand of the oppressor, and reconciling between people. All of this counts among acts that bring one closer to Allah. This is why the prophets took it on, as did the rightly guided caliphs after them. Accordingly, the scholars agreed that it is among the collective obligations, since people's affairs cannot function properly without it."Fath al-Bari (13/121).