Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) states that the Messenger of Allah (peace and blessings be upon him) said: "Envy (ghibtah) is permissible regarding two men: (1) one whom Allah gave wealth and then enabled him to spend it in the right way; (2) one whom Allah granted wisdom, who teaches it and also judges by it."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب آداب القاضي / 20164