It is narrated from Sayyiduna Abdullah bin Abbas (may Allah be pleased with them both) that the Messenger of Allah (peace and blessings be upon him) said: "When Allah intends good for someone, He grants him understanding of the religion."
Related hadith on this topic