The outcome is a rare Supreme Court setback for Trump, who had won repeated victories in emergency appeals since he took office again in January.