WASHINGTON—A federal judge in Maryland said Wednesday that President Trump’s public remarks about immigrants and personal insistence on placing a citizenship question on the census could help determine whether the government intended to discriminate against Hispanics by adding the query.

Justice Department attorneys had insisted over the past year that Mr. Trump had no involvement in adding the citizenship question. They argued that anything the president said about immigrants was legally irrelevant, since there was no proof Commerce Secretary Wilbur Ross, who oversees the census, even knew Mr. Trump’s views.

Government lawyers “repeatedly represented to this Court that Secretary Ross, and not President Trump, acted ‘as the sole decisionmaker’ as it relates to the addition of a citizenship question to the Census, and that, as a result, any evidence of statements made by candidate, President-elect, or President Trump suggesting discriminatory animus towards immigrant communities was not relevant,” U.S. District Judge George Hazel’s order said.

But with the Trump administration now seeking to replace its entire legal team, Judge Hazel said the new attorneys would have to account for potential discrepancies between the government’s prior positions and “recent developments” since the Supreme Court, ruling last month in a separate case from New York, blocked the citizenship question on procedural grounds. The court found nothing wrong in principle with a citizenship question, but ruled that Mr. Ross “contrived” its rationale in claiming he needed more data to protect minority voting rights. The decision sent the issue back to the Commerce Department.

On the eve of the Supreme Court’s June census ruling, however, a federal appeals court in Richmond, Va., told Judge Hazel to begin proceedings on the equal-protection claim, after an unrelated lawsuit in North Carolina turned up evidence tying a deceased Republican political consultant to Trump administration efforts to add the citizenship question.