Sacred prostitution is another institution which was very widespread in antiquity. In some places ordinary respectable women went to a temple and had intercourse either with a priest or with a casual stranger. In other cases, the priestesses themselves was sacred harlots. Probably all such customs arose out of the attempt to secure the fertility of women through the favour of the gods, or the fertility of the crops by sympathetic magic.
Source: Marriage and Morals, 1929, by Bertrand Russell
More info.: https://russell-j.com/beginner/MM04-030.HTM