I wouldn't say it's always based on religious doctrine (although it's certainly a common source). Like for example, ancient China had multiple different religions (such as Taoism, Buddhism, Confucianism) and which one is more popular fluctuates, but chastity before marriage is a pretty commonly...