The department’s lawyers had for months defended assertions by Commerce Secretary Wilbur Ross that the Justice Department sought the citizenship question so that it could acquire better data to enforce the 1965 Voting Rights Act. Three federal courts ruled that that explanation was clearly an excuse for some other goal, and last month the Supreme Court agreed, saying the question could be asked only if the department came up with a believable rationale.

The Justice Department abandoned the fight after that ruling, telling a federal judge that the battle was over “for once and for all,” only to be blindsided last week by President Trump, who said on Twitter that the statements were “fake.” Mr. Trump suggested that the head count could be delayed until he found a way to add the citizenship question, perhaps by printing an addendum that could be tacked onto the questionnaire.

That prompted a cascade of troubles. On Wednesday, Justice Department lawyers returned to a Maryland court that was hearing a case against the question to recant their admission of defeat. “The tweet this morning was the first I had heard of the president’s position on this issue, just like the plaintiffs and Your Honor,” Joshua Gardner, a lawyer working on the census issue, told Judge George J. Hazel of United States District Court.

Mr. Gardner and other department officials told Judge Hazel and a second judge in Manhattan overseeing another census lawsuit that the search for a way to place the question on the census would continue. But lawyers for opponents of the question pounced on that declaration on Friday, arguing that the Justice Department had insisted repeatedly — including to the Supreme Court — that it was essential to wrap up the dispute by the end of June, lest the census be delayed for lack of time to print questionnaires and other forms.

The Supreme Court relied on that deadline, the plaintiffs noted, in leapfrogging the legal appeals process to take the case directly from a lower federal court to a hearing before the justices. But having lost the legal battle, they argued, the Justice Department says there is ample time to hunt for some other way to achieve its goal.

The government’s “‘heads I win, tails we’ll see’ approach undermines confidence in both their ability to conduct the 2020 census and public confidence in the rule of law,” the plaintiffs argued. “If any ordinary litigant engaged in such conduct, sanctions would be the minimum relief provided. And defendants are no ordinary litigants.”

The Justice Department has been under fire from the moment Mr. Trump took office. In district and appellate court, the department has defended the Trump administration against litigation spurred by the president’s travel ban, his immigration policies and his stance on the Affordable Care Act.