The Prophet ﷺ said, "When Allah intends good for a servant, He grants him understanding of the religion."
حدثنا عفان قال حدثنا حماد يعني ابن سلمة قال أخبرنا جبلة بن عطية عن عبد الله بن محيريز
أن النبي ﷺ قال إذا أراد الله بعبد خيرا فقهه في الدين
Its isnad is sahih. Jablah bin Atiya Filastini is trustworthy, praised by the scholars, and Abdullah bin Muhayriz is trustworthy, one of the well-known devout worshippers. The hadith was narrated by Bukhari 13/293, no. 7312, Fath, in the chapter on holding fast to the religion, regarding the Prophet's ﷺ saying, "A group of my nation will always remain triumphant." And by Muslim 2/718, no. 1037, in the chapter on zakat, on the prohibition of begging, and by Ibn Majah 1/80, no. 221.