Some African governments have found these laws useful, Mr. Akwei said, to suppress parts of civil society and preserve their power. “These were all laws that were designed to benefit the colonial powers and make sure that their subjects knew their place,” he said.
Conservative religious constituencies, both Christian and Muslim, have also influenced some governments: While evangelical Christianity is influential in Uganda, conservative Islam has helped shape attitudes toward gay people in Sudan and Somalia, where homosexuality is punishable by death.
Are there prospects for further change?
Conservative social mores remain a force across much of the continent. Many Kenyans hold strong anti-gay views — 90 percent of Kenyans said society should not accept homosexuality, according to a 2013 Pew survey — and the judges in last month’s decision in Kenya argued that homosexuality clashed with traditional values.
An attempt to strike down Botswana’s anti-sodomy laws failed in 2003, but activists made “incremental” progress later, said Anna Mmolai-Chalmers of Lesbians, Gays and Bisexuals of Botswana. Botswana, which is regarded as one of Africa’s most stable democracies, changed its employment act to prevent discrimination against LGBT people in 2010, and the High Court ruled in favor of a transgender man who sought legal recognition as a male in 2017.
And last September, President Mokgweetsi Masisi of Botswana expressed tentative support for gay people, saying, “Just like other citizens, they deserve to have their rights protected.”
Ms. Ghoshal, the Human Rights Watch researcher, said that she was optimistic that an appeal could prevail in the Kenya case, and Ms. Mmolai-Chalmers said activists in Malawi and Mauritius had been encouraged by the gradual steps that led to change in Botswana.
“That’s the thinking at the moment: Let us claim the rights we know we are accorded as citizens, slowly, before we challenge decriminalization,” she said.