((Imām Bukhārī narrates) that) Humaidī narrated to us, he said: Sufyān narrated to us, he said: Ismā'īl ibn Abī Khālid narrated to me — apart from this, Zuhrī narrated to us, he said: I heard Qais ibn Abī Hāzim, he said: I heard 'Abdullāh ibn Mas'ūd, may Allāh be pleased with him, saying that the Prophet ﷺ said:
Hasad (ghibtah) should be done only regarding two persons: one, a person to whom Allāh has given wealth, and he spends it in the rightful channels; the other, a person to whom Allāh has given wisdom, and he judges according to this wisdom (knowledge) and teaches it to the people.
حَدَّثَنَا الْحُمَيْدِيُّ قَالَ: حَدَّثَنَا سُفْيَانُ قَالَ: حَدَّثَنِي إِسْمَاعِيلُ بْنُ أَبِي خَالِدٍ - عَلَى غَيْرِ مَا حَدَّثَنَاهُ الزُّهْرِيُّ - قَالَ: سَمِعْتُ قَيْسَ بْنَ أَبِي حَازِمٍ قَالَ: سَمِعْتُ عَبْدَ اللهِ بْنَ مَسْعُودٍ قَالَ: قَالَ النَّبِيُّ ﷺ
لَا حَسَدَ إِلَّا فِي اثْنَتَيْنِ: رَجُلٌ آتَاهُ اللهُ مَالًا فَسُلِّطَ عَلَى هلَكَتِهِ فِي الْحَقِّ، وَرَجُلٌ آتَاهُ اللهُ الْحِكْمَةَ فَهُوَ يَقْضِي بِهَا وَيُعَلِّمُهَا.
Reference: Sahih Al Bukhari 73