It is narrated from Sayyiduna Ibn Abbas (may Allah be pleased with them both) that the Messenger of Allah (peace and blessings be upon him) said: "Whomever Allah intends good for, He gives him understanding of the religion."
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 10741