A former serviceman who was suffering with severe mental illness tried to build a submachine gun to lead a "rebellion", a court heard.
Llifon Huw Jones, 32, from Penygroes, Gwynedd, became increasingly unwell after the Brexit referendum in 2016.
He became convinced he had rights under 13th Century laws drawn-up in the Magna Carta to launch an uprising, Caernarfon Crown Court heard.
He was detained indefinitely in hospital after admitting charges.
These were attempting to make a weapon, possessing items to convert weapons, having a knife in a public place and two charges of threatening behaviour.
Prosecutor Anna Pope said his behaviour began to spiral following the Brexit vote, and he "wanted to protect liberty".
Jones became obsessed with a defunct part of the Magna Carta - the body of English law first signed in 1215 - that he claimed gave him the right to seize government buildings and to rebel against the state and Crown.
The court heard he intended to establish a group called the North Wales Lawful Rebellion and made inquiries about advertising in a local newspaper and hosting meetings to rally support.
In January 2018, he then posted notices on the entrances of neighbours' properties, stating his intention to seize them under Section 61 of the Magna Carta.
The worried home owners contacted police, who discovered the cache of weapon-making material at the home he shared with his grandparents.
Police uncovered a partially completed submachine gun, two homemade shotguns, tools for converting inactive firearms, and books explaining how to build guns.
Psychiatrist Dr Fouad Basa said Jones' actions were "largely influenced' by his mental illness, and a hospital order was the best sentencing option.
Defence barrister Elen Owen said he was a former serviceman and had suffered from post-traumatic stress disorder.
Ms Owen said since starting hospital treatment had an insight into his actions.
She added that the defendant "is absolutely mortified" that others might have felt threatened.
Judge Timothy Petts told Jones he continued to "pose a danger to the public", but also accepted his actions were the result of a schizophrenic mental condition.
He will be detained in hospital not be released "until it is safe" for him to return to the community.