Legal experts said it was rare for a judge to put conditions on what jurors can say after a trial has concluded. Lynne M. Abraham, a former judge, said that it makes sense to ask the jurors to respect the privacy of the jury room but that it’s not clear they can be ordered to keep quiet.

“The judge can’t prevent them,” she said, “but they will probably want to do the right thing,”

When the judge did not make the names of the jurors public at the end of the trial, several news organizations, including The Philadelphia Inquirer, The Associated Press, The Washington Post and The New York Times, filed a motion requesting access to the names, citing their First Amendment right.

Both the prosecution and the defense requested that the judge deny the motion, saying that the release of names could affect a second trial.

“Although jurors may choose to come forward to the media of their own volition, that should be their choice,” Kevin R. Steele, the district attorney for Montgomery County in Pennsylvania, wrote in response to the media motion. “In this case,” he added, “there is a substantial probability that the rights of the parties to a fair trial will be prejudiced by the release of the names of the jurors from the recent mistrial.”

During a hearing on the matter on Tuesday, the judge said he needed to balance the media’s First Amendment rights with the possibility that disclosing the names could chill the selection of a second jury. He also cited the media’s treatment of the jurors during the trial, saying journalists had tried to photograph and speak to the jurors despite his order prohibiting anyone from contacting them.

Typically, judges might withhold names of jurors to protect their privacy during the trial but would release them when a trial concludes, if not earlier. Juries have been most often kept anonymous in situations where judges are worried about their safety, such as in cases involving defendants associated with gangs or organized crime.