The one constant in his manic existence was a fascination with law enforcement and the criminal justice system, they said. Since he was a boy, Mr. Ransom had desperately wanted to become a police officer, recalled Frank Rios, a lifelong friend. But Mr. Rios said questions about Mr. Ransom’s mental health kept him from pursuing the job.

Mr. Rios was not the only associate of Mr. Ransom’s who recalled emotional and mental health problems. Neighbors of Mr. Ransom’s mother in Ocean Hill, who had adopted him out of foster care, recalled her frustration with his tendency to act out in odd ways. She had taken him to counseling and had gotten him medication, one neighbor, Clemente Williams, said.

“He wouldn’t take his meds and his mother would say he would go a little cuckoo,” Ms. Williams said. “He seemed to be an all-right guy but a little off.”

Mr. Ransom’s sister, Patricia Rush, 46, also recalled that Mr. Ransom took medication for a mental condition as a child and was supposed to continue taking it into adulthood, though she did not recall what disorder he had. “He is supposed to be on medication right now,” she said.

Quirks that appeared innocent in childhood grew darker and more serious as Mr. Ransom matured. After he failed to pursue a career as a police officer, he went to peculiar — and sometimes illegal — lengths to make inroads in the city’s justice system. He was prone to wearing fake policing gear in public. He donned it one morning in 2016 as he tried to nonchalantly enter Brooklyn’s 77th Precinct offices.

Wearing a tactical vest and a fake badge that read “Super Police,” Mr. Ransom tried to gain access to restricted areas of the building. He was arrested, convicted of impersonating a law enforcement officer and spent 20 days in jail.

Mr. Ransom was also convicted in 2012 of fraudulently claiming to be a college intern in order to gain access to restricted areas of the Kings County courthouse, including judges’ chambers.