Masturbation is treated differently in different religions but many devout people in less tolerant religions suffer agonies os sexual frustration when they can control the urge to masturbate and suffer agonies of guilt when they can't.
Masturbation is often considered sinful due to ambiguous interpretation of Genesis 38:10. This attitude has caused unnecessary guilt and unhappiness throughout the ages and still causes problems among strict Christian groups today. Liberal Christians are more relaxed about masturbation and may think it helps to control sexual temptation.
Lay Buddhists may masturbate but monks and nuns should stay celibate.