The ruling paves the way for the president to sign into law what is one of the continent’s most restrictive pieces of anti-LGBTQ legislation.