A man who had his guns confiscated after writing on social media that he would “shoot any woman any time for any reason” has had the weapons returned to him by a judge.

Charles Donnelly, 23, also posted a photo of himself holding two AK-47-style rifles with the caption, “One ticket for Joker please”, a reference to the movie, online.

Authorities in his home city of Seattle, in the US, were so alarmed by the posts – which also included fantasies of hurting women – that they used new red flag laws to seize the 23-year-old’s weapons.

The haul included three handguns and three rifles, including an AK-47-style rifle and magazines.

But the whole arsenal – all legally owned – was returned to him after he appealed the action in court, claiming the posts were jokes meant only for his friends.

A judge accepted his arguments and handed them back, The New York Times reports.

Mass shootings in America Show all 8 1 /8 Mass shootings in America Mass shootings in America Camden shootings – 1949 Howard Unruh killed 13 people, including three children, during a 12-minute walk through his neighborhood on September 6, 1949, in Camden, New Jersey, when he was 28 years old. The incident became known as the "Walk of Death". Unruh was found to be criminally insane and died in 2009 after a lengthy illness at the age of 88, following 60 years of confinement. Alamy Mass shootings in America University of Texas tower shooting – 1966 Charles Whitman killed 17 people and injured 31 others in Austin, Texas. After stabbing his mother and wife the night before, he headed to the University of Texas, where he opened fire on people in the campus and streets from the observation desk. He was shot dead after a policeman and civilian reached the scene. Austin History Center, Austin Public Library Mass shootings in America Easter Sunday Massacre – 1975 James Ruppert killd 11 family members in his mother's house, which included his mother, brother and his wife, as well as their eight children. He used a magnum, two handguns and a rifle. Mass shootings in America Wilkes-Barre shootings – 1982 Former prison guard, George Banks, shot dead 13 people in Pennsylvania, including five of his own children. AP Photo/Times Leader Mass shootings in America Wah Mee massacre – 1983 Three men, Kwan Fai Mak, Wai-Chiu Ng, and Benjamin Ng, killed 13 people who were in Seattle's Wah Mee gambling club. YouTube/KIRO 7 News Mass shootings in America San Ysidro McDonald's massacre – 1984 James Huberty killed 21 people and injured 19 others after he walked in a McDonald's in San Diego. He was shot dead by a sniper after 78 minutes of him entering the restaurant. Alamy Mass shootings in America Palm Sunday massacre – 1984 Ten people were shot dead from handguns at close range in a New York home. A baby girl was the only survivor after convicted dealer, Christopher Thomas, shot three women, one teenage girl and six children in their Brooklyn home. Thomas was convicted of manslaughter and cleared of murder. He was released from prison after 32 years. Mass shootings in America Edmond post office shooting – 1986 Patrick Sherrill, a postal worker at the Edmond post office in Oklahoma, killed 14 co-workers and injured 6 others, before he shot himself. Oklahoma Highway Patrol Collection

Kim Wyatt, the prosecutor who lead the action against Mr Donnelly, told the October hearing that his posts “implied [a] threat of a mass shooting”.

She had him read some of his other online messages back to the court. “Kill all woman,” said one. “Prowling the Seattle streets for women to assault,” came another.

“We would ask the court to balance the community safety needs versus the temporary deprivation of Mr Donnelly’s rights to possess firearms,” Ms Wyatt said.

But the gun-owner claimed the messages were, in fact, mocking online misogyny and violence.

The Joker post, he said, was riffing on a larger “tickets to Joker” meme in which internet users stereotyped the kinds of person who would attend the movie. One of the guns in the picture, he said, was not even his.

Derek Smith, his lawyer, highlighted the fact that Donnelly had no criminal record and described the weapons seizure as an intrusion on both his First Amendment and Second Amendment rights.

“It is crystal clear to Mr Donnelly that the state is looking over his shoulder, watching everything that he posts, and that if they don’t follow the joke, then they are going to come after him for a violation of his rights,” Mr Smith said.

Judge Averil Rothrock took his side. “The statute is not written such that the court can give the benefit of the doubt to law enforcement at the expense of Mr Donnelly,” she said.

Speaking afterwards, the gun-owner said he was not an activist and supported some use of red flag laws.