A federal judge Monday denied a request by an alleged Russian agent to be released on bail before trial but chastised prosecutors for making salacious allegations about Maria Butina they later walked back.

U.S. District Judge Tanya Chutkan said she was “dismayed” after reading the messages prosecutors relied on to make the allegations, which the judge said were clearly meant as a joke. The mistake “really makes it very, very difficult to have a fair trial,” Judge Chutkan told prosecutors, who late Friday retracted allegations Ms. Butina had offered sex in exchange for a position.

The judge also criticized an attorney for Ms. Butina for frequent media appearances in which he has discussed the merits of the case, and the judge issued a gag order prohibiting him from speaking publicly about the evidence in the case. “Your comments have crossed the line,” Judge Chutkan said.

The developments are the latest twist in a case that has linked together Russian officials, a young Russian gun-rights activist and student in Washington, the American gun lobby, a Rockefeller heir and a longtime conservative political activist from South Dakota.

Ms. Butina, 29 years old, was arrested in July and accused of conspiring to cultivate relationships in the U.S. with influential conservatives and gun-rights activists to advance Moscow’s agenda.