A man who pleaded guilty as a teenager to locking his carer in a room and raping her has won his bid for a retrial after a court found he might not have understood he committed a crime.

Now aged 21, the Townsville man was 10 days shy of his 17th birthday when he allegedly cornered the woman "and committed various sexual assaults upon her including raping her by penetrating her vagina with his penis", according to a Court of Appeal judgment.

The childcare worker was trapped in the corner of a room and allegedly raped by a teenage boy. Credit:Shutterstock

At the time of the alleged attack, the boy "had already displayed behavioural problems [and] was in the care of the Department of Children Services".

In 2016, he pleaded guilty in the Childrens Court in Townsville to three counts of rape, two counts

of wilful exposure and one count of sexual assault, assault occasioning bodily harm and deprivation of liberty.