It is mentioned in a Hadith that Rasulullah sallallahu alayhi wa sallam said: “When Allah desires good for a person, He gives him an understanding of the Deen. I am a distributor of knowledge and Allah is the real giver.” (Bukhari and Muslim)
It is also related in a Hadith that when a person dies, his deeds are cut off, except the reward of three deeds:
sadaqah-e-jaariyah (continuous charity – example endowing a property, building, well, or musjid in the name of Allah), (2) knowledge which benefits the people (for example by teaching, writing books, etc.), (3) a pious child that makes duas for the deceased. (Muslim) The meaning of this Hadith is that the reward of all good deeds ceases once the person dies. This is so because a dead person cannot do any good, so why should he get any reward? However, these three deeds are such that their rewards continue after death as well. These deeds are such, that they continue even after death because in sadaqah-e-jaariyah the people continue benefitting from it. Similarly, the benefit of knowledge also continues. And pious children make duas for their parents, so this act also remains after one’s death.