The court rejected laws that impose up to seven years in prison for same-sex relationships, stating they were unconstitutional.
The move contrasts with Kenya's recent ruling against campaigners seeking to overturn laws on gay sex.
Angola, Mozambique and the Seychelles have all scrapped anti-homosexuality laws in recent years.
After three judges came to the decision unanimously, Judge Michael Elburu delivered the verdict.
"Human dignity is harmed when minority groups are marginalized," he said.
He labelled laws banning gay sex as "discriminatory" and said: "Sexual orientation is not a fashion statement. It is an important attribute of one's personality."
The law has been in place since 1965 when it was brought in by the colonial British government.
The case was brought to court by a student who argued society had changed and homosexuality was more widely accepted.
Activists welcomed the decision and described it as a significant step for gay rights on the African continent.