The top court said the Trump administration’s justification for the question appeared “contrived”.