The High Court has upheld an intellectually disabled man's appeal against a custody order that has kept him in prison for more than 25 years.

In 1987, Gregory John Yates was sentenced to seven years' jail for sexually assaulting a young girl at a Perth shopping centre.

But despite finishing the sentence in 1993, he has remained in jail because he was being "held at the governor's pleasure" following an order made by the Supreme Court judge who sentenced him.

Yates has been described as having the mental capacity of a 14-year-old.

Prior to the sexual assault, he had been convicted of minor crimes including stealing cigarettes and newspapers.

Aside from a conviction for gross indecency, Yates had no prior criminal history of violence or sexual assault.

But in 1986, the 25-year-old sexually assaulted a seven-year-old girl in the toilets of a shopping centre.

He was arrested and initially denied the charges, but changed his plea to guilty after giving evidence at his own trial.

He was convicted of aggravated sexual assault and deprivation of liberty.

In sentencing Yates, former Supreme Court judge Robert Wallace described him as "a danger to the community and in particular to young people".

"You appear unable to control your deviant sexual instincts," he said.

Justice Wallace made an order under the Criminal Code that Yates be held indefinitely after finishing his sentence.

"It may be that you can receive and accept counselling and treatment for your unfortunate deviant conduct whilst you are incarcerated and, in that event, earn your release upon a reasonable period of parole," he said.

"That will be up to you."

Severity

Yates appealed against the severity of the sentence, and the WA Court of Criminal Appeal agreed to a slight reduction in his jail term to reflect time already served.

But it refused to reverse Justice Wallace's order that Yates be held indefinitely.

The case came to the attention of Legal Aid WA in 2011 and it began working with the now 52-year-old to launch an appeal.

That bid was heard in the High Court this week.

In her submission, Yate's lawyer, Karen Farley, argued the initial jail term was adequate punishment for the crime.

She said the custody order constituted a significant miscarriage of justice and also raised issues regarding the way Yates was dealt with.

In one example, a psychiatrist who provided an assessment of Yates before his sentencing had only spent a few minutes with him.

After considering the submission, the High Court upheld the new appeal and quashed the custody order.

The court found the sentencing judge did not have evidence to support the order, and the original appeal should have been upheld.

The judgment means Yates will be released from custody without parole or supervision.

The court says it is up to the State Government to apply for restrictions to be placed on Yates, such as staying away from certain areas or people.

The court has stressed it is not suggesting those restrictions need to be enacted in this case.

The WA Attorney-General has been contacted for comment.