ANNAPOLIS, Md. β€” A judge ruled Tuesday to unseal some documents in the case of a man who has pleaded guilty but not criminally responsible to killing five people at a Maryland newspaper, but she declined to make public many records involving his mental health.

The ruling by Judge Laura Ripken came after the Capital Gazette and Baltimore Sun sought the release of a number of records that have remained under seal. Scores of other documents were released after Jarrod Ramos pleaded guilty to first-degree murder and other charges in October. The second phase of his trial, when a jury is scheduled to decide whether he is not criminally responsible due to his mental health, is scheduled for March.

Ripken said public access to information in legal proceedings is important, but must be balanced with the defendant's right to fair trial.

The Capital newspaper's review of Maryland court records found an apparent loophole that allows documents filed electronically to be kept from the public. The judge underscored at Tuesday's hearing that records filed confidentially in the electronic format should be followed by a motion to seal them.

Ripken said she didn't believe attorneys on either side were trying to hide anything. She also noted that much of the information will become public during the trial later this year or after its conclusion.

"All the lawyers are trying to ensure is a fair trial ensues," Ripken said.

Lawyers in the case argued that the mental health records go to the heart of the case. They said making them public could prejudice the jury.

"It relates to the ultimate issue in this case," said Elizabeth Palan, an attorney representing Ramos.

Anne Colt Leitess, the Anne Arundel County state's attorney, told the judge that details about Ramos' mental health must be "jealously guarded" to ensure a fair trial and prevent Ramos from having reasons to appeal. Leitess said releasing the records could "literally poison this case."

Nathan Siegel, an attorney representing the newspapers, contended that rules on the disclosure of court records are supposed to favor the public, not attorneys who make deals to keep information out of the public eye. He also said the fact that information in the records is central to the case should favor public disclosure.

"We strongly believe that generally the materials that are filed in an important case like this should be open," Siegal said.

Ramos pleaded guilty but not criminally responsible in October to killing John McNamara, Gerald Fischman, Wendi Winters, Rob Hiaasen and Rebecca Smith in the June 2018 newsroom rampage. A second phase of his trial for a jury to determine whether he is criminally responsible is scheduled for March.

During a pretrial hearing in October, Ripken said a report from the state health department concluded Ramos is legally sane. But Ramos' lawyers say experts for the defense have reached a different conclusion.