The justices, with two dissenting votes, said Monday that the policy can take full effect even as legal challenges against it make their way through the courts.