Read this:
LGBT rights in Uganda - Wikipedia
The extreme homophobia does not seem to be religiously based at all:
'The climate in Uganda is one of extreme homophobia; many political leaders have used openly homophobic rhetoric, and have said that homosexuality is "akin to bestiality", was
"brought to Uganda by white people" and is "un-African".
Simon Lokodo, Minister for Ethics and Integrity, is known by Ugandan LGBT activists as "the country's main homophobe. He has suggested that rape is more morally acceptable than consensual sex between people of the same sex, has accompanied violent police raids on LGBT events and actively suppresses freedom of speech and of assembly for LGBT people.
[28]'
The initial legislation was of course put in place by Britain, during its time as a colonial ruler.