Monastics
The aim of all of these is to enable one to conduct oneself in such a way as is most conducive to the attaining of enlightenment.
The rules are voluntarily undertaken, and if a monastic feels unable to live up to them, s/he is free to leave the Order at any time, which is considered much more honorable than hypocritically remaining in robes while knowingly infringing a rule.
There are four basic rules, infringement of which is termed parajika or "defeat," and involves immediate and irrevocable expulsion from the Order. [Even masturbation breaks a rule, but sexual intercourse is out of the question.]
Complete sexual continence is considered an essential feature of Buddhist monastic life. Intercourse whether heterosexual or homosexual is automatically a defeat offense. A monastic who performs such an act is considered to have expelled him or herself from the Order. Any acts of a sexually unbecoming nature falling short of intercourse result in suspension and require expiation. Novices who break their training in this respect are defrocked/disrobed.
The same principle applies to the Mahayana schools and, of course, to nuns where they exist. [Some regard the Theravada fully ordained nuns' line in to have lapsed leaving only novices or ten ten precept nuns.]
There is no such thing as a "married monastic," but in certain schools, particularly in Japan, a form of "quasi-monasticism" with married teachers who retain a form of ordination is permitted under certain conditions. This is of no relevance to the Theravada Order. Part 2: Laypeople