It is one of the most ancient forms of prostitution, supposedly already practiced among Sumerians. In ancient sources (Herodotus, Thucydides) there are many traces of sacred prostitution, starting perhaps with Babylon, where each woman had to reach, once a year, the sanctuary of Militta (Aphrodite or Nana/Anahita), and there have sex with a foreigner, as a sign of hospitality, for a symbolic price.
A similar type of prostitution was practiced in Cyprus (Paphus) and in Corinth, Greece, where the temple counted more than a thousand prostitutes (hyerodules), according to Strabo. It was widely in use in Sardinia and in some of the Phoenician cultures, usually in honour of the goddess Astarte (or Ishtar). Presumably by the Phoenicians, this practice was developed in other ports of the Mediterranean Sea, like in Erice (Sicily, in Locri Epizephiri, Crotone, Rossano Vaglio, Sicca Veneria and other towns. Other hypotheses regard Asia Minor, Lydia, Syria and Etruscans.
It was common in Israel too, but some prophets, like Hosea and Ezekiel, strongly fought it; it is assumed that it was part of the cults of Canaan, where a significant proportion of prostitutes were male.
According to the Bible, the Canaanite peoples had a system of religious prostitution. This is seen, for example, in Genesis 38:21, where Judah asks Canaanite men of Adulam "Where is the harlot, that was openly by the way side?". The Hebrew original employs the word "qedsha" in Judah's question, as opposed to the standard Hebrew "zonah". The word "qidsha" is derived from the root Q.D.Sh, which signifies uniqueness and holiness; thus it probably represents a religious prostitute, a term uncommon among the Israelites, but known to them from the neighboring people and used in communication between them.
It is also thought that the pagan priests called qedeshim (the masculine form of "qedsha") in the Torah regularly engaged in homosexual acts. The phrase "mahir kelev", "the pay of a dog" (Deuteronomy 23:18-19) refers to the payment to a male prostitute. Male prostitutes in that time and place usually serviced men, not women. Moreover, Leviticus 18 contains a number of prohibitions regarding sexual relations with different people (some of them incestuous) that are thought to be relevant to Canaanite habits of religious prostitution inside family.
In ancient Rome, the priestesses of goddess Vesta had the two duties of always maintaining lit the goddess' fire, and to initiate young boys to sex at the moment of tonsura. The famous Rea Silvia, mother of Romulus and Remus, was one of these. The use of maintaining an always lit fire has been recorded in many coastal temples, and has been ideally connected with the preference (or exclusive licence) granted to sailors to use these services. It has been supposed that these fires should indicate the route to sailors, exactly like modern lighthouses.
In Greece, Solon instituted the first Athen's brothels (oik`iskoi) in the 6th century BC, and with the earnings of this business he built a temple dedicated to Aprodites Pandemo (or Qedesh), patron goddess of this commerce. The Greek word for prostitute is porne, derived from the verb pernemi (to sell), with the evident modern evolution. The procuring was however severely forbidden.
There is a practice in southern India called "devadasi". It involves adolescent girls from villages to be married to a deity or a temple. After they reach puberty they are made to practice prostitution for upper-caste members. This practice was made illegal only in 1988.
Some practitioners of Neopagan religions such as Wicca incorporate sex into their religious practice, but this is by free will and is not formalized as pre-modern temple prostitution was. Wiccans regard the use of sex as a requirement for initiation or advancement in degree as an abuse.