Abdullah bin Amr bin As reported,

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

Azami 1236

Sahih

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

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

الأعظمي 1236صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Knowledge
Chapter
Warnings in matters of knowledge
Section
Raising of knowledge and appearance of ignorance and tribulations at the end of time
Numbering
Jami al-Kamil 1236 (2nd edition)
Azami 1236