MOMBASA, KENYA—A Kenyan court on Thursday upheld the use of anal examinations to determine a suspect’s sexual orientation, dismissing the argument that the procedure amounts to torture and degrading treatment.

There was no violation of rights or the law, Mombasa High Court Judge Mathew Emukule said.

“I find no violation of human dignity, right to privacy and right to freedom of the petitioners,” he said.

Two men had sought a court ruling to stop enforced anal examinations and HIV tests of men accused of being gay after they were subjected to the procedures.

The two were arrested in a bar near Ukunda along Kenya’s Indian Ocean coast in February 2015 on suspicion of engaging in gay sex, which is a criminal offence in Kenya. They still face the charges, and, if convicted, could face 14 years in jail.

In their petition, the men said the anal examinations and HIV and hepatitis B tests they were forced to have amounted to being subjected to torture and degrading treatment.

The judge said the petitioners should have used their lawyers to seek injunction orders to avoid undergoing the tests.

“I sat in court holding my chin in disbelief,” said Eric Gitari, the executive director of the Kenyan National Gay and Lesbian Human Rights Commission, which has supported the petition.

He said the men will appeal.

“It’s so painful when we are trying to encourage the gay community to go to court to affirm their rights; the courts are, instead, affirming violation of their rights,” Gitari said.

Thursday’s judgment means that someone can be arrested on a rumour that they are gay and subjected to these tests, he said.

“Do we want to use the nation’s scarce resources on this?”