Bryan Moles, left, as he deprated court with his attorney Eugene Ohm on June 1. (Jessica Gresko/AP)

A Pennsylvania man accused of bringing a military-style rifle to Trump International Hotel in May was ordered by a federal judge Thursday to undergo a psychiatric exam after prosecutors alleged he was in the throes of a debilitating mental illness.

Bryan Moles, 43, pleaded not guilty June 22 to a firearms charge after being arrested in the District on May 31 after police found an AR-15 rifle, a handgun and more than 90 rounds of ammunition in his 2017 black BMW parked at the Trump International Hotel. Moles told authorities he had come from Ebinboro, Pa., to meet with President Trump.

Prosecutors originally consented to Moles’s release from custody June 2 by a U.S. magistrate, pending further court proceedings, on condition that he undergo treatment at a veterans facility in Atlanta.

But Magistrate Robin M. Meriweather of Washington revoked that decision June 15, after prosecutors alleged Moles committed a litany of violations and had undergone a downward psychological spiral. He posted “cryptic” and “disturbing” messages on social media about the June 14 shooting of a congressman at a baseball practice in Alexandria, referenced a song about suicide by firearm, and threatened a potential witness by voice mail, prosecutors said.

A federal court filing shows weapons recovered by police from Bryan Moles home in Pennsylvania. (AP/AP)

He also flooded his VA hospital room in Georgia, refused antipsychotic medication, used drugs and returned to the District in violation of court orders, the government said.

“The evidence establishes that the defendant is deep in the throes of a debilitating mental illness,” Assistant U.S. attorney Michael J. Friedman wrote in court papers.

“Close acquaintances have expressed grave concern that the defendant’s mental health condition may cause harm to himself or others,” Friedman wrote, adding, “Release pending trial would pose an intolerable danger to the community under these circumstances.”

Assistant Federal Defender Loui Itoh argued that the government had not shown that Moles was mentally incompetent — which would mean he did not understand the court proceedings and could not assist in his defense — and that his only meaningful violation was refusing medication that had given him suicidal thoughts when it had been previously prescribed for him.

Itoh said Moles was cooperative with physicians in Georgia but that he had trouble sleeping in the hospital because as an emergency room physician and former Navy corpsman, he associates hospitals with high-stress work.

Still, in arguments Thursday and last week, Friedman told U.S. District Judge Richard J. Leon that there was no reason to believe Moles would follow up on his promise to go home to Pennsylvania for treatment, and that “in any event, a thorough determination of competency” to stand trial was needed first.

Leon granted the government’s request and ordered that Moles undergo a competency evaluation at a federal psychiatric facility within 30 days.

In court papers, prosecutors said Moles told authorities he came to Washington from his home on May 31 to “bring down big medicine business and big pharmacy” and did not plan to leave 1600 Pennsylvania Ave. until he saw the president.

He told police, according to court papers, that he suffers from post-traumatic stress disorder, had refused medication and was treating himself with marijuana.

Prosecutors in court filings also alleged that Moles in recent days “evidenced multiple personalities.”