Hispanics have “legitimate fear” of the Trump administration and its quest to query Americans about their citizenship on the 2020 Census, Justice Sonia Sotomayor said Tuesday, as the Supreme Court debated whether President Trump has the power to add the question back in to the decennial count.

The government’s lawyer, Solicitor General Noel Francisco, was less than two sentences into his argument when Justice Sotomayor pounced for the first time, keeping up a steady stream of questions suggesting Mr. Trump and his team invented reasons to ask about citizenship, and that Hispanics, in particular, will refuse to take part, souring the all-important survey.

“Are you suggesting they don’t have, whether it is rational or not, that they don’t have a legitimate fear?” Justice Sotomayor demanded.

The court’s conservative justices fired back, pointing out that citizenship questions have been a part of the census almost since the beginning, first as part of the basic form sent to every household and, since 1960, as part of a longer form sent to a smaller sampling of homes.

They wondered what’s changed that makes the Commerce Department’s move to make it controversial to add the question back into the full census questionnaire going to all homes next year.

“It’s not like this question or anybody in the room is suggesting the question is improper to ask in some way, shape or form,” said Justice Neil M. Gorsuch.

For anti-Trump activists, the president is trying to scare people away from an accurate count. For the president and his team, the information is critically important to enforcing voting rights laws, and there’s no other assured way of getting good data other than to ask about it on the census.

The government said the question has been asked before, provides important information and besides, refusing to answer the census is illegal, so catering to the potential for Americans’ to take illegal action is fraught with its own perils.

Mr. Francisco said if the court were to side with the president’s opponents now, it would open the door for other lawsuits, giving an objector’s veto over questions such as sex or gender.

Instead, Mr. Francisco said, the court should trust the Commerce Department to find ways to reach refuseniks through outreach and personal visits. And he said getting the citizenship data is worth it, even if it means more hassle and the potential for fewer responses.

In terms of presidential power, the case is far less important than some of the others to come before the justices during Mr. Trump’s tenure, such as the travel ban. Yet the array of anti-Trump states and activists arguing against the president underscores the stakes.

A skewed census would siphon billions of dollars in federal aid and even political power in the form of elected representatives away from states with high non-citizen and Hispanic populations, the president’s opponents argued.

“On trial is not only the accuracy of a full Latino count, but also the foundation of our democracy,” said Arturo Vargas, CEO of the National Association of Latino Election and Appointed Officials Educational Fund. “No other issue before the Supreme Court will have more direct consequences for the nation’s Latinos than the one before the court today regarding the 2020 census.”

The controversy began when Commerce Secretary Wilbur Ross decided early last year that he was going to restore the citizenship question to the full 2020 survey. He said he was doing it at the behest of the Justice Department, which wanted better data to enforce the Voting Rights Act.

But at three separate trials in lower courts, it became clear his motives may have been different than what he publicly said.

The liberal-leaning justices said Tuesday that Mr. Francisco was making a valiant effort to rehabilitate Mr. Ross’s bungling but to no avail. They said Mr. Ross’s attempts to recruit another department to ask him to ask about citizenship were ham-handed and said his decision-making memo was too truncated to be of much use.

“It did really seem like the secretary was shopping for a need,” Justice Elena Kagan said. “You can’t read this record without sensing this need was a contrived one.”

Yet the president’s opponents seemed to stumble when Justice Ruth Bader Ginsburg pointed out that Congress has ultimate power of the census and could have taken control, ordering which questions to ask or to leave off. Indeed, Congress has forbidden religion questions.

“Who should decide?” Justice Ginsburg said. “Congress is silent. Should the court then step in?”

The Democrat-led House of Representatives sent its top lawyer, Douglas N. Letter, to argue against Mr. Trump. But Mr. Letter struggled to give an answer to Justice Ginsburg’s question, instead blaming Mr. Ross for refusing to testify to Congress about his moves.

Chief Justice John G. Roberts Jr. was not convinced, saying given the extensive arguments in the courts there can’t be much left unknown at this point.

“What more does Congress need?” he wondered.

The four liberal justices peppered the Trump administration, but the conservative justices spent their time challenging the president’s opponents, which court watchers took as a signal Mr. Trump is likely to prevail.

If the justices do side with Mr. Trump it would be a major reversal from the lower courts, where a series of judges from New York to Maryland to California have ruled against the president.

Tuesday’s case sprang from the New York decision, by Judge Jesse M. Furman, an Obama appointee to the bench.

But Judge Richard Seeborg’s ruling in California is the more wide-reaching. Judge Seeborg, also an Obama appointee, not only ruled that the Trump administration cut corners, but he ruled there was no way to salvage the situation before the 2020 census begins.

He issued an outright ban on including the citizenship question in the 2020 count, saying Mr. Trump can’t get “another bite at the apple.”

“The inclusion of the citizenship question on the 2020 Census threatens the very foundation of our democratic system and does so based on a self-defeating rationale,” Judge Seeborg wrote.

The citizenship question is dear to Mr. Trump’s heart. His campaign had at one point even bragged about his inclusion of the question, touting the move in a fundraising email to supporters.

His administration has bungled things from the start, though. Each of the lower court judges ruled Mr. Ross had already been working to add the citizenship question, apparently at the behest of the White House, well before the Justice Department asked for the question to be included.

The lower court judges said asking about citizenship is not inherently evil — it couldn’t be, since the question was part of the full census up until 1950, was part of the so-called “long form” census through 2000, and even now is still asked on the Census Bureau’s American Community Survey, which goes to a sample of households each year.

But the judges said the motives and means matter, and there the Trump administration cut too many corners. One judge concluded that perhaps 5 percent of people would refuse to fill out the 2020 census because of the question.