A 21-year-old man with a history of sleepwalking has been told he may need treatment after a jury found he was asleep when he sexually assaulted his friend’s girlfriend.

Dale Kelly was found not guilty of sexual assault by penetration by reason of insanity after he sleepwalked into the couple’s bedroom, got into their bed and touched the woman intimately.

A jury at York crown court took just over two hours to decide that Kelly had committed the offence but was suffering from the sleep disorder parasomnia at the time, meaning he was not responsible for his actions.

Kelly hung his head and wept in the dock as the jury returned its verdict. Family members sitting in the public gallery gasped and comforted each other.

The week-long trial heard that Kelly had been to a nightclub with his friend and the woman before they returned to a house in North Yorkshire on the morning of 17 April 2017.

Kelly fell asleep during the journey in the taxi and went straight to bed when they arrived at the house. Around an hour later the woman awoke to find him in the bed she was sharing with her partner.

She said she believed Kelly had sexually assaulted her and called the police. Kelly said he was dreaming at the time and thought he was with a woman he was dating.

He left the house after the incident and sent a message to his friend a short time later, which read: “I promise right now I have no fucking clue what’s going on, I’m still wanting to wake up and for this to be in dreamland.”

After his arrest, Kelly underwent tests, during which he experienced episodes of parasomnia, which can include sleepwalking.

The court heard that he had suffered from parasomnia since childhood and experts said he was “possibly” or “likely to be” suffering from the disorder at the time of the alleged assault but they could not say for certain.

Eleanor Fry, defending, said her client could not say what happened that morning as he was asleep at the time.

The special verdict of not guilty by reason of insanity can be returned in circumstances where the jury find the defendant has committed an act but is suffering from a condition – in this case parasomnia – that means they cannot be responsible for their actions at the time.

Following such a verdict, the court can order the defendant to be admitted to a hospital, make a guardianship, supervision or treatment order, or order an absolute discharge.

The judge Simon Hickey said: “This has not been an easy case and not a straightforward case. It is an unusual case.” He outlined the sentencing options available to him and adjourned the case until a later date when he said experts would address the issues.

He said doctors in the case believed Kelly’s “mental disorder” was treatable and needed treating. He said: “My sentencing options are limited. At the moment I’m leaning towards a hospital order but I will wait to hear what the experts say.”

Kelly, from Dalton-le-Dale, County Durham, was granted conditional bail and will be sentenced on 23 September.