Chief Justice John Roberts wrote the splintered opinion, and it seemingly will be up to him - if the Commerce Department offers new justification - whether it passes muster and the question appears on the census form.
Agencies must offer "genuine justifications for important decisions, reasons that can be scrutinized by courts and the interested public," Roberts wrote in a section of his opinion joined by the court's four liberals.
"Accepting contrived reasons would defeat the purpose of the enterprise. If judicial review is to be more than an empty ritual, it must demand something better than the explanation offered for the action taken in this case."
Roberts was the only member of the Supreme Court on the term's closing day to be on the prevailing side in both the census case and the court's ruling on partisan gerrymandering. It was emblematic of the chief justice's new role at the center of the court, now that Justice Anthony Kennedy has retired.
But the ruling caused considerable confusion. It was unclear whether there would be time for the administration to come up with an acceptable justification for the question and obtain judicial approval.
The administration had said a decision was needed by the end of June to add such a question; other officials have said there is a fall deadline.
Justice Department spokeswoman Kelly Laco called the decision a disappointment but said in a statement after the ruling that the government "will continue to defend this administration's lawful exercises of executive power."
After Thursday's ruling was announced, President Donald Trump seemed annoyed by the court's demand for more explanation and frustrated by the time limitation.
He tweeted that he has inquired with "the lawyers" whether the census may be delayed until the Supreme Court receives the necessary information to make a "final and decisive decision" on the matter.
"Can anyone really believe that as a great Country, we are not able the ask whether or not someone is a Citizen," Trump's tweet says. "Only in America!"
Those who challenged the citizenship question were pleased by the ruling but said they were cautious given the uncertainty about whether the administration might still prevail. Opponents have said the citizenship question would result in an undercount of millions of people who fear acknowledging that a noncitizen is part of their household.
While the Supreme Court's deliberations centered on whether Commerce Secretary Wilbur Ross had authority to add the question and had followed legal procedures, challengers also want to reopen in lower courts whether he had discriminatory intent.
The court's decision in Department of Commerce v. New York came in the most debated Trump administration initiative to reach the high court since last year's 5-to-4 decision upholding the president's ban on certain travelers from a group of mostly Muslim countries.
There was even more at stake here, and the debate was filled with partisan politics: An undercount estimated by census officials of more than 8 million people would most affect states and urban areas with large Hispanic and immigrant populations, places that tend to vote for Democrats.
The decennial count of the nation's population determines the size of each state's congressional delegation, the number of votes it receives in the electoral college and how the federal government allocates hundreds of billions of dollars.
Challengers included Democratic-led states and civil rights and immigrant rights organizations.
Roberts's bottom line - that a lower court was right to say Ross had not provided an adequate explanation for adding the citizenship question - was joined by liberal Justices Ruth Bader Ginsburg, Stephen Breyer, Sonia Sotomayor and Elena Kagan.
They agreed that Ross' stated reason for adding the question - that it was requested by the Justice Department to aid in enforcement of the Voting Rights Act - fell apart upon examination.
"That evidence showed that the Secretary was determined to reinstate a citizenship question from the time he entered office; instructed his staff to make it happen; waited while Commerce officials explored whether another agency would request census-based citizenship data; subsequently contacted the Attorney General himself to ask if DOJ would make the request; and adopted the Voting Rights Act rationale late in the process," Roberts wrote, reflecting what U.S. District Judge Jesse Furman and other judges have found.
In Furman's view, Roberts wrote, "this evidence established that the Secretary had made up his mind to reinstate a citizenship question 'well before' receiving DOJ's request, and did so for reasons unknown but unrelated to the VRA."
Ross had also met with some of the White House's hard-line immigration foes about the issue.
Roberts said that Ross deserved great deference in deciding how to run the census but that "reasoned decisionmaking under the Administrative Procedure Act calls for an explanation for agency action. What was provided here was more of a distraction."
In his January opinion, Furman said the question could not be added without resolving its "legal defects."
He had a long list of requirements - gathering adequate information and statistics, submitting a report to relevant congressional committees, and considering relevant evidence - as well as providing Ross' "real rationale."
Some found the decision puzzling about what comes next.
"I don't understand what the court decided," said Senate Majority Leader Mitch McConnell, R-Ky. "I think it's kind of confusing," and "my general rule of thumb is if I'm confused about something I don't comment."
The court's conservatives concurred with Roberts in the first part of his opinion, in which he said Ross had the right to ask a citizenship question and that he has wide discretion over conducting the census.
Justice Clarence Thomas said Roberts should have stopped there.
"For the first time ever, the Court invalidates an agency action solely because it questions the sincerity of the agency's otherwise adequate rationale," Thomas wrote. "Echoing the din of suspicion and distrust that seems to typify modern discourse, the court declares the secretary's memorandum 'pretextual.' "
He criticized Furman's opinion that said Ross and his aides "acted like people with something to hide."
"I do not deny that a judge predisposed to distrust the secretary or the administration could arrange those facts on a corkboard and - with a jar of pins and a spool of string - create an eye-catching conspiracy web," Thomas wrote.
He was joined by Justices Neil Gorsuch and Brett Kavanaugh.
Justice Samuel Alito said the court should have stayed out of Ross' decision-making.
"To put the point bluntly, the Federal Judiciary has no authority to stick its nose into the question (of) whether it is good policy to include a citizenship question on the census or whether the reasons given by Secretary Ross for that decision were his only reasons or his real reasons," Alito wrote.
The court's liberals, on the other hand, thought Roberts did not go far enough. Ross' decision should simply have been set aside, they said.
Evidence presented to Ross by his in-house experts on the census "indicated that asking the question would produce citizenship data that is less accurate, not more," wrote Breyer.
Groups who had opposed adding the question expressed cautious optimism that the decision against adding the question will stick.
"On the census, the Trump administration's lies went so far that even this Supreme Court had to say no," said Michael Waldman, president of the liberal Brennan Center for Justice. "If this leads to a result with no citizenship question, that would be a very welcome outcome, and it would also preserve the status quo. This should have been an easy case, and in the end, it was."
Dale Ho, director of the American Civil Liberties Union's Voting Rights Project, said there is not enough time for the administration to try to come up with a new legal rationale for adding the citizenship question.
"If they try to do this over the weekend, it's a sign of cutting corners and not reasoned decision-making," Ho said. "There really is not time. If the administration tries to rush it, that's clearly a red flag."
Lower-court judges have said Ross violated administrative law and the Constitution's enumeration clause by proposing to ask the citizenship question of each household. Those issues were at stake before the Supreme Court.
But discoveries in the case after the court heard oral arguments raised new and different issues - principally, whether the administration's motivation was, at its core, discriminatory.
Judges in Maryland and New York have said they would consider new allegations regarding the assertion that Ross' actions violated equal-protection guarantees and was part of a conspiracy to drive down the count of minorities.
The information came from the files of a deceased Republican political operative. Thomas Hofeller, who had been in touch with some census officials at the start of the Trump administration, wrote a memo that said adding the question might help Republicans and white voters in subsequent redistricting decisions based on the census data.
Sign up for the daily JWR update. It's free. Just click here.