Allaah may preserve a servant’s children and grandchildren due to his righteousness, as was said regarding the saying of the Elevated;
{…and their father was a righteous man } [Al Kahf: 82]
That they were preserved due to their father’s righteousness [1].
Muhammad ibn al Munkadir stated: ‘Indeed Allaah preserves the children and grandchildren of a righteous man, even the town that he lives in and the area around it. They continue to be preserved by Allaah.
Ibnul Musayyib said to his son: ‘My son! I will increase my prayers for you, hoping that Allaah will preserve me by preserving you.’ He then recited the saying of Allaah:
{…and their father was a righteous man } [Al Kahf: 82]
‘Umar ibn ‘Abdul ‘Azees stated: ‘There is not a believer who dies except that Allaah preserves him/her by preserving his/her children and grandchildren.’
--------------------------------------------------------------------------------
[1] The Ayah reads: "And as for the wall, it belonged to two orphan boys in the town; and there was a treasure under it belonging to them; and their father was a righteous man, and your Lord intended that they should attain their age of full strength and take out their treasure as a mercy from your Lord. And I did them not of my own accord…"
Ibn Katheer stated: “This verse is evidence that a righteous man is preserved by the preservation of his offspring, and they benefit from the blessings of his worship in the life of this world and the next, they benefit from his intercession for them, raising them to the highest level of Jannah so that they may be the pleasure of his eyes, as is affirmed in the Qur-aan and Sunnah.”
http://subulassalaam.com