Once a mad woman was brought to the court of Umar. The charge of adultery was established against her. Umar was inclined to sentence her to the penalty of being stoned to death but he deemed it necessary to consult Ali before delivering the judgment. Ali advised that the penal law of Islam was applicable only in such cases where the person concerned was in proper senses, and could be held responsible for his action. Where a person was not in proper senses, he could not be held accountable for his actions. The view of Ali was accepted and the mad woman was let off.
"When a person dies, his works end, except for three: ongoing charity, knowledge that is benefited from, and a righteous child who prays for him."
Prophet Mohammed (PBUH)
"The best of what a man leaves behind are three: a righteous child who supplicates for him, ongoing charity the reward of which reaches him, and knowledge that is acted upon after him."
Sunan Ibn Mājah
"Every day two angels come down from Heaven and one of them says, 'O Allah! Compensate every person who spends in Your Cause,' and the other (angel) says, 'O Allah! Destroy every miser.'"
Sahih Bukhari