On Saturday, an Egyptian court convicted eight men for "inciting debauchery." Their crime was their appearance in a video that went viral for depicting what is ostensibly the country's first same-sex wedding party. The court sentenced each of the men to three years in prison.

The video, which surfaced on YouTube in various forms, shows two men exchanging rings and embracing while onlookers cheer—something Egypt's chief prosecutor said was "shameful to God" and "offensive to public morals" when the men were charged in September.

But Egypt, a country that has a hard time acknowledging the existence of gay citizens within its borders, has no laws against homosexuality. Instead, the law that was used to prosecute the men is one with roots in British colonialism—one meant to rid the newly independent Egypt of the licensed brothels that had existed under British rule. Known as Law 10/1961 on the Combating of Prostitution, it banned prostitution of all forms, in a brothel or elsewhere.

"Both the Wafd, the main nationalist party, and the religious conservatives including the Muslim Brotherhood saw the existence of licensed brothels where Egyptian women served British soldiers as a comprehensive national humiliation," the LGBT rights activist Scott Long, who is based in Cairo, told me in an email.  

The result was passing a law that criminalized promiscuity in general. Not only did the legislation outlaw female prostitution, but it also prohibited what it called "debauchery"—without actually defining what might constitute debauched behavior. Without looking for evidence that money had changed hands, police began arresting men for engaging in gay sex under the debauchery provision. "The motives didn't matter so much as the fact that the elastic language permitted the law to expand with the scope of moral indignation," Long, who is working on a book on the subject, noted. As he summed it up: "A moral panic led to a ridiculously broad and vague law."   

Later, Egyptian courts would expand the law's scope. A decision in the 1970s by the Court of Cassation, the highest court of legal interpretation in the country, definitively stated that the debauchery provision meant sex between two men, regardless of whether or not money was exchanged. Under this interpretation, "debauchery" would mean that the sex would be "habitual" and "without discrimination." Specifically, that meant that for a citizen to be prosecuted, he had to have sex with more than one man in a three-year period.

Sex, however, can be a hard thing to prove. According to Long, sometimes those who are arrested are tortured so police can get their confessions as proof of "habitual" sex, in absence of other evidence. In other cases, as in the gay wedding instance, forensic anal examinations—"medical tests"—are used to "prove" homosexual acts. "It's a textbook example," Long said, "of how poorly laws on sex are written in many countries, and how moral panics can change how those laws are read and enforced."