“I am prepared to add you to my lawsuit against Eric Hartley,” Mr. Ramos wrote in a letter dated Jan. 30, 2013. “I am satisfied you did not directly solicit his column about me, but I think you know who did. Given all that has transpired, I think you have many such secrets, and I would ask you to surrender them.”

After Mr. McCarthy obtained another order prohibiting him from contacting her, Mr. Ramos sued the lawyer himself. He also appealed the order against contacting the former classmate, which was granted, Mr. McCarthy said.

Mr. Ramos graduated from Capitol Technology University in 2006 with a degree in computer engineering. For several years, he held a job as an information technologist with a subcontractor for the Bureau of Labor Statistics. But in July 2014, six months after Enterprise Information Services took over the contract, he was terminated at the request of the government, representatives of the company said.

The contractor said it was not aware of the reason for the request. Mr. Ramos, who had worked on the help desk answering employee questions about computer glitches and how to reset passwords, then filed a lawsuit against his former employer, saying that money was not paid to him.

On Friday in court, Judge Thomas Pryal told Mr. Ramos, “There is a certain likelihood you are a danger.” Mr. Ramos did not speak and showed no emotion, staring into the camera and blinking occasionally.

Mr. Ramos lived in a small brick apartment building in Laurel, Md. A neighbor on Friday said he was so reserved that most people did not know he was a resident. He was oddly expressionless, she said, almost as if he were putting forth a calm facade. When her daughter asked him for jumper cables to help start her car, he refused.

“I said, ‘This guy is not right,’” said the neighbor, who identified herself only as Veronica. “What’s wrong with this guy?”