Sean Bernard Downey has been given a Treatment Order for the attempted robbery of Queen's Road Morrisons in January 2024 and two other offences.
The 23-year-old has been detained indefinitely for attempting to rob the Morrison's Daily supermarket in St Helier with an imitation gun.
Downey - wearing a balaclava - threatened the cashier and a customer who was being served, but was chased out of the shop by the customer.
He then ran into a nearby field and attempted to hide his clothing and imitation firearm.
Downey arrested and remanded in custody before being transferred to a secure facility in the UK, where he was assessed.
Under the treatment Order, he cannot be discharged without a future court decision.

The 23-year-old was also sentenced in the Royal Court for an assault and a separate instance of importing £74,436 of Class A and B drugs into Jersey, both in 2023.
Downey and 22-year-old co-defendant Kenneth Leonard Skinner punched and kicked a man whilst he was on the ground outside The Oxford pub on the corner of New Street in St Helier in October 2023.
Both men were found guilty of common assault by a jury following a five-day trial at the Royal Court.
A month after the assault, Jersey Customs and Immigration also intercepted a parcel addressed to Downey with £74,436 worth of drugs concealed inside.
It contained 2,435 MDMA pills, 2.02 grams of MDMA rock, 16.19 grams of amphetamine and a small amount of cocaine.
Initially, he denied knowledge, but when he was presented with evidence, both financial and through phone messages, he pleaded guilty to the importations.
Image supplied by States of Jersey Police
States of Jersey Police, DC Daniel Grigoras, OIC in the case, says their thoughts are with the victims of this violent and threatening behaviour.
"We will not tolerate such acts in our community.
"Ensuring the safety of our Islanders is, and always will be, our top priority."

Jury finds Shay John Bester guilty of offences including rape
African community groups express 'disappointment' with Deputy Ozouf sentencing
Island Energy to return to Royal Court over Mont Pinel gas explosion
Jersey to introduce legal limit for PFAS in drinking water
Jersey Electricity drops St Martin solar farm idea
PPC won't move to block Deputy's return to States Assembly
Jersey's next government urged to create laws preventing exploitation of workers
Philip Ozouf sentenced to 120 hours community service