The Court of Appeal has ruled that forced anal examinations used to determine whether gay men engaged in sex is illegal.
Two men were arrested in 2015 in Ukunda, Kwale County on suspicion of having sex.
The men said they were subjected to forced anal examination by police and staff at a public hospital in Mombasa on orders of a Kwale court to determine if they had engaged in anal sex and were homosexual. They also said authorities forced them to submit to HIV tests.
The men took the case to court and argued the tests violated their constitutional rights. In 2016, the High Court in Mombasa dismissed the petition.
But in a landmark ruling, on Thursday, appellate judges Alnasir Visram, Wanjiru Karanja and Martha Koome overturned the High Court's decision and declared the tests and examinations were illegal.
"The right to privacy particularly not to have one's privacy invaded by unlawful search of the person is closely linked to the right to dignity, those rights in our view extend to a person not being compelled to undergo a medical examination," the judges said.
Same-sex sexual activity is outlawed in Kenya and punishable by 14 years in jail.