The ruling by the country’s supreme court deals a blow to one of President Trump’s closest allies in Latin America.