That delusion will be part of a package of evidence that Mr. Gottlieb says he plans to submit to the court that prove Mr. Comello is not guilty by reason of mental defect. Mr. Gottlieb is seeking to have the court place Mr. Comello in psychiatric treatment, rather than prosecute him on murder charges. Mr. Comello is being held in protective custody as he awaits trial.

Prosecutors in the Staten Island district attorney’s office declined to comment.

Mr. Comello took handcuffs with him to Todt Hill on March 13, Mr. Gottlieb said, but his plan was foiled when Mr. Cali refused to submit to a citizen’s arrest. Instead, Mr. Gottlieb said, the Gambino leader reached toward his waistband. Fearing for his life, Mr. Comello shot Mr. Cali 10 times and fled, Mr. Gottlieb said.

QAnon, a baseless conspiracy theory that originated on internet message boards, played a key role in Mr. Comello’s descent into mental instability, his lawyer said. It claims, among other things, that America is controlled by a “deep state,” that prominent Democratic politicians are pedophiles and that John F. Kennedy Jr., who died in a 1999 plane crash, is secretly alive and will run for president in 2020.

At Mr. Comello’s first court appearance in March, he displayed symbols and phrases associated with QAnon scrawled on his hand in pen. He first began to take an interest in political conspiracy theories, Mr. Gottlieb said, in the weeks after Mr. Trump’s 2016 election.

“Mr. Comello’s support for ‘QAnon’ went beyond mere participation in a radical political organization,” Mr. Gottlieb wrote. “It evolved into a delusional obsession.”

Driven by that obsession, Mr. Gottlieb said, Mr. Comello began early this year to attempt citizen’s arrests of people he believed to be associated with the deep state. In February, Mr. Comello twice tried to conduct his own arrest of Mayor Bill de Blasio, including one instance in which he showed up at Gracie Mansion, the mayoral home in Manhattan.

Not long after that incident, Mr. Comello sought the help of United States marshals at Federal District Court in Manhattan, and asked that they help him to arrest two California Democrats, Representatives Maxine Waters and Adam Schiff, both of whom he believed were in the vicinity. He was rebuffed.