The court ruling gives lawmakers 18 months to adjust the current law, Agence France-Presse reports.
The verdict is in line with an opinion given seven months ago by the Inter-American Court of Human Rights that said homosexual couples have the same rights as heterosexual ones to marry.
“We continue to deploy actions that guarantee no person will face discrimination for their sexual orientation or gender identity, and that the state’s protection be given to all families under equal conditions,” Costa Rican President Carlos Alvarado wrote on Twitter.
Alvarado, a centrist, was elected in April after defeating an evangelical preacher, Fabricio Alvarado, who ran on a platform against same-sex unions.
Costa Rica is a majority Roman Catholic country and a high number of evangelical lawmakers who oppose gay marriage sit on the legislative assembly.
“I see it as not very likely that in 18 months the Legislative Assembly will work out a law,” said Enrique Sanchez, a lawmaker in President Alvarado’s Citizen Action Party, according to AFP.
“What I see happening is that the norm (the gay-marriage ban) will simply be declared unconstitutional in 18 months’ time,” added Sanchez, who is also the country’s first openly gay member of the legislature.
Magistrate Fernando Castillo said that if the legislature does not change the law within the time frame, the ban will cease to exist and gay marriage will automatically become legal, according to the Associated Press.