LGBTQ activists attend a court hearing in Nairobi in February.Khalil Senosi / AP

NAIROBI—When the Nigerian writer Unoma Azuah was growing up in the Asaba Niger Delta, she once asked her grandmother about a teenage boy in her village with an effeminate aura whom others would tease, calling him a girl. Her grandmother replied that she didn’t understand why people bullied him.

“In her time, there were men who dressed as women, and they were seen as spiritual people, with a special gift,” Azuah told me. When Azuah was young, her grandmother would joke about a man who took a wife but spent most of his time with his best friend, another man, in private. “It was nothing outrageous,” Azuah said.

But when Britain colonized large swaths of Africa in the late 19th and early 20th centuries, when Azuah’s grandmother was growing up, it imposed penal codes that punished actions “against the order of nature”—code for homosexual acts—with up to 14 years in prison. These would become the first anti-gay laws on the continent, laws that are now being targeted by African LGBTQ-rights activists who argue that homophobia, not homosexuality, was an import from the West.

That effort suffered a setback this week, as Kenya’s High Court unanimously ruled that the country’s own British-era penal code against unnatural acts, adopted into law at Kenya’s 1963 independence, does not violate the country’s 2010 constitution. That document explicitly guarantees equal protection to all people, freedom of expression, and freedom from discrimination, as well as requires affirmative-action programs for minorities and marginalized groups.

Britain’s own laws against homosexual acts were revoked more than 50 years ago, and in 2013, the country passed legislation allowing for same-sex marriage. But around the world, its tradition of criminalizing homosexuality lives on, with versions of British penal codes still on the books in former colonies such as Egypt, Zimbabwe, Ghana, and Tanzania. Sudan prescribes the death penalty for homosexuality. So does Mauritius and parts of southern Somalia and Nigeria.

Some countries are now rejecting those anti-gay laws. Last year, India’s Supreme Court struck down its own colonial-era law banning sex “against the acts of nature.” Months earlier, a court in Trinidad did the same for a law that punished same-sex intercourse with up to 25 years in prison.

The Kenya petition had been a test case for a new approach. When I began covering LGBTQ rights in Africa, in 2014, those who campaigned against sodomy laws argued that they violated international and national law, or basic human rights and dignity. More recently, I’ve noticed a different argument take hold: Confronted with the common refrain that homosexuality is fundamentally un-African, activists have sought to argue the reverse—that homophobia is un-African.

Same-sex relationships are not new to Africa. A century ago, it was not uncommon for a woman of Azuah’s Igbo tribe to marry another woman and cohabit. Similar women-to-women marriages have been documented in at least 30 different tribes across the African continent. Men of the Maale tribe in Ethiopia would sometimes have sex with other men.

But when nations such as Kenya, Uganda, Ghana, and Nigeria won independence, they inherited British anti-sodomy penal codes, which remain the law of the land across many former colonies. Of the 72 countries worldwide that still criminalize homosexuality, 38 of them were at some point under British rule, a new book notes. Many of these colonial-era codes are still enforced: Kenya prosecuted 595 people under these laws from 2010 to 2014, according to government figures.

Over time, these laws left a psychic mark. Most Africans find homosexuality unacceptable, according to a 2013 Pew Research Center survey. Religious leaders, legislators, and even presidents refer to homosexuality as un-African. Opponents portray homosexuals as preying on young boys and sometimes girls to convert them to homosexuality. Today, in Azuah’s hometown of Asaba, Nigeria, rather than people treating homosexuality as benign or even unique, she said, “they say it’s a disease. Be careful so you don’t get recruited.”

It was only in 2003 that Kenya eliminated corporal punishment for same-sex conduct. A few years ago, anti-LGBTQ activists tried, unsuccessfully, to introduce a bill that would have increased the maximum sentence for Kenyans convicted of homosexual acts to life in prison, up from 14 years. The draft bill even prescribed death by stoning to any foreigners convicted of “recruiting” Kenyans into performing same-sex acts.

“The devil in the name of foreign agents comes and introduces an alternative sex,” one of the bill's supporters, Vincent Kidaha, told me in 2015. “Foreigners are the people who are nurturing our very locals to this act.” The belief that homosexuality is foreign is one reason why Kenyan LGBTQ-rights activists cringed when Barack Obama publicly chastised Kenya for its poor record on LGBTQ equality during a 2015 visit to the country. The West’s most powerful leader, a man of African heritage no less, defending homosexuality in Africa was seen by many as further proof of a global gay agenda. In the days following Obama’s visit, one of Kenya’s leading newspapers was rife with editorials denouncing the president’s attempt to interfere with African traditions.

The struggle to acknowledge and reject colonial-era edicts over things such as sexuality continues, the Kenyan writer Mukoma Wa Ngugi said last year while speaking at an African literature festival in Berlin. “The British empire in one sense ended, but its language is now the language of the world,” he said. That’s a sentiment I’ve heard LGBTQ-rights defenders echo and reframe to criticize not just colonial language, but the morals espoused through it. “We have to undo the notion of what culture is,” as well as “what it means to be African,” Kari Mugo, the operations manager at the National Gay and Lesbian Human Rights Commission of Kenya, told me.

Such calls to reexamine laws and traditions that were first imposed by the British have been accompanied by a new willingness on the part of Britain itself to acknowledge its part in criminalizing homosexuality around the world. In April, under pressure by U.K. LGBTQ-rights groups, British Prime Minister Theresa May apologized for Britain’s role in introducing anti-homosexuality laws to its former colonies and urged leaders to reform what she called the “outdated” laws. Some smaller former British territories such as Belize have done so, with South Africa going so far as to legalize gay marriage in 2006 and Malta following suit in 2017.

For many LGBTQ Africans I’ve met, the movement to decolonize African relationships carries an emotional weight at least as strong as the desire to reject English as a colonial language or to demand the return of African artifacts—looted during colonial times—from museums throughout the Western world. Akin to reclaiming their physical heritage, to strike down laws against homosexuality would be to reimagine what life for LGBTQ people in Kenya, Uganda, and other former British colonies might have been like without a century or more of British-imposed homophobia.

The argument is catching on: Prominent academics and human-rights advocates have begun drawing attention to the colonial history of these laws in recent months. Last year, the South African lawyer and human-rights professor Wendy Isaak cited the colonial origin of Ghana’s anti-homosexuality penal codes in a report for Human Rights Watch. And the professors of human rights Jill Cottrell Ghai and Yash Pal Ghai took the argument to the Kenyan public, writing in the Nairobi daily newspaper The Star that implementing the British colonial-era penal code involves “prying into the most private aspect of the person’s life: What they do in their own bedroom.”

“The idea that homosexuality is not African has no basis in fact ... In fact, what is un-African is the law against same-sex relations,” they wrote.

But not everyone agrees. Charles Kanjama, a lawyer for the Kenya Christian Professionals Forum, which defended the anti-homosexuality law in court, argues the majority of Kenyans favor these laws. “Homosexuality is seen as a very moral perversion—a taboo,” he says.

Beyond this latest ruling, many other rights enjoyed by LGBTQ people in other parts of the world will remain elusive in Kenya. Same-sex marriage isn’t even on the agenda, say activists. Kenyan law still forbids same-sex couples to adopt, and that’s unlikely to change anytime soon.

At the courthouse in Nairobi in advance of the decision, LGBTQ activists held up rainbow flags and greeted one another with smiles and kisses on the cheek. Anticipating that judges would strike down the law, they were hopeful other former British colonies in Africa would reconsider their own legislation: Ghana, Nigeria, Mauritius, and Botswana are all countries that activists have suggested might soon consider taking legal action of their own.

Yet after the ruling, Yvonne Muthoni, who directs the Kenya chapter of a coalition of businesses that support LGBTQ-inclusion, walked out of the courtroom in silence. She embraced a colleague, who said they would appeal the decision. “This,” the colleague told her,” is definitely not the end.”

We want to hear what you think about this article. Submit a letter to the editor or write to letters@theatlantic.com.