Esteban Santiago, 26, initially blamed his actions on government mind control but later said he had been "on the dark web" communicating in "jihadi chat rooms," the FBI testified in court during a detention hearing on Tuesday, according to the Sun Sentinel, Florida.
An FBI agent confirmed Santiago used a 9mm gun in the massacre at Fort Lauderdale-Hollywood International Airport on January 6. He had practiced firing the weapon at a gun range in Alaska in the months prior to the attack.
The agent said it was the same weapon that Alaskan police seized when Santiago was hospitalized for six days for mental health problems in November, after the shooter turned himself in at an FBI office in Anchorage.
Santiago told agents at the Anchorage office that his "mind was being controlled by the government and he was being pushed to watch terrorist propaganda," the Broward County Sun-Sentinel reported.
Prosecutors said when Santiago was released from psychiatric care, doctors believed he was "stable." He was prescribed anti-anxiety medication and melatonin. The weapon, confiscated by police, was returned to Santiago in December, according to agents.
Santiago, an Iraq war veteran, was first interviewed by FBI agents and detectives at the airport.
"During the interview, the defendant admitted he planned the attack," prosecutor Ricardo De Toro told the court.
"At various points...he said he carried out the attack because of government mind control," Del Toro told the judge. "But he later said he did so because of ISIL...after participating in jihadi chat rooms."
ISIL or ISIS is another name for Islamic State.
Santiago has not been formally charged but may face charges of shooting five people and injuring six others at the Terminal 2 baggage claim. He could face the death penalty if convicted.
US Magistrate Judge Lurana Snow ruled Santiago will remain in custody while investigations continue.
He is due back in court January 30 for an arraignment hearing.