New court filings raise questions about how a man charged with robbing a bank in Algiers this summer bought a firearm used in the heist despite his history of mental illness.

The records show that the man, Mohammed El-Hanini, had been treated and even hospitalized for unspecified mental health issues, and his defense attorney says he may be unfit to stand trial.

However, that history did not prevent El-Hanini from obtaining the 9mm pistol he has admitted firing into the ceiling of the bank during the robbery — a weapon he told the FBI he bought last year at a Kenner gun show.

El-Hanini, a 38-year-old naturalized citizen, confessed to robbing the First Bank and Trust branch on Gen. de Gaulle Drive because he “needed money to travel back to Jordan,” according to the FBI.

El-Hanini walked into the bank on July 31 and handed a teller a bag and a note that read, “Large bills only or I will use the gun,” authorities said.

The man later told investigators he lost patience during the stickup and, believing the teller was not taking him seriously, fired his handgun at the ceiling, according to a criminal complaint filed by FBI agent Crystal Bender.

El-Hanini got more than $6,000 and drove away in a black Lincoln Town Car that had been parked in front of the bank, according to court documents. Two New Orleans police officers spotted the car a few miles away and pulled it over, recovering the pistol and cash.

El-Hanini told the FBI he purchased the gun in December 2014 from “the Kenner Gun Show,” according to the criminal complaint. The document did not spell out any further details of the purchase.

At gun shows, licensed firearms dealers are required to conduct background checks on buyers. However, that requirement does not extend to the many private sellers attending those events, said Laura Cutilletta, a staff attorney with the Law Center to Prevent Gun Violence, a legal advocacy group.

“Some states have closed that loophole,” Cutilletta said, “but Louisiana has not.”

A federal grand jury indicted El-Hanini last month on counts of bank robbery and discharging a firearm during a violent crime. His trial is tentatively set for Oct. 19.

Defense attorney Gary Bizal filed a court motion Monday seeking to have El-Hanini evaluated at a federal medical facility to determine whether he is competent to stand trial. Bizal said he has received “medical records that show the defendant has a history of mental illness,” including “periods of hospitalization.”

Follow Jim Mustian on Twitter, @JimMustian.