It is the first legal hurdle thrown up to the Trump administration as it seeks to send thousands of migrants to a detention facility on the naval base near Cuba.