Legal just means they won't arrest/execute you for being in a same sex relationship. Same sex marriage means they state will officially recognize you as married.
There's also significant input from American Evangelicals contributing to these laws. For instance, Scott Lively an evangelical anti-gay activist, helped push for Uganda to penalize same-sex relationships with the death penalty. And Islam only makes up 13.7% of Uganda.