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."

Nine years in jail for man who raped woman he met on dating app
From drought to deluge: Channel Islands receive a month's rain in a week
Feedback wanted on JFRS four-year safety plan
Free clubs and food provision amongst children's asks of government
Film telling the story of Jersey shared with secondary schools
Traitors-themed fundraiser raises £14,500 for Tiny Seeds
Orange the World March: "Walk with us, talk with us"
Man jailed for 'sustained pattern of abusive behaviour'