I heard the Prophet ﷺ say, "There is no envy except in two cases. A man whom Allah has given wealth and empowered to spend it in the cause of truth, and a man whom Allah has given wisdom by which he judges and which he teaches to others."
سمعت النبي ﷺ يقول: لا حسد إلا في اثنتين رجل آتاه الله مالا فسلطه على هلكته في الحق، ورجل آتاه الله حكمة فهو يقضي بها ويعلمها.
Bukhari related it in the Book of Zakat (1409), and Muslim in the Book of the Prayer of Travelers (816), both by way of Ismail bin Abu Khalid, who said, "Qays (that is, Ibn Abu Hazim) narrated to me," from Ibn Masud, and he related the hadith.