Abdullah bin Amr bin As reported,

I heard the Messenger of Allah ﷺ say, "Allah does not take away knowledge by snatching it from people, but rather He takes away knowledge by taking the lives of the scholars, until, when no scholar remains, people take ignorant ones as their leaders. They are asked, and they give rulings without knowledge, so they go astray and lead others astray."

Muslim 6796

Sahih

حدثنا قتيبة بن سعيد حدثنا جرير عن هشام بن عروة عن أبيه سمعت

عبد الله بن عمرو بن العاص يقول

ا سمعت رسول الله ﷺ يقول إن الله لا يقبض العلم انتزاعا ينتزعه من الناس ولكن يقبض العلم بقبض العلماء حتى إذا لم يترك عالما اتخذ الناس رءوسا جهالا فسئلوا فأفتوا بغير علم فضلوا وأضلوا

مسلم 6796صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Knowledge
Chapter
Raising of knowledge, its removal, and the emergence of ignorance and tribulations at the end of time
Numbering
Darussalam 6796
Muslim 6796