Sayyiduna Abu Huraira (may Allah be pleased with him) narrated from the Messenger of Allah (peace and blessings be upon him), he (peace be upon him) said: "When Allah intends good for someone, He grants him understanding in the religion."
Related hadith on this topic