HELENA, Mont. — The Montana Supreme Court has unanimously overturned a Great Falls man’s incest conviction, saying he should have had access to crucial information about his daughter’s mental illness that would have allowed him to challenge whether she was telling the truth.

The court ordered a new trial last week, noting a prosecutor heavily redacted a report written by the child’s neuropsychologist before turning it over to the defense, and that the judge sealed the child’s medical records without reviewing them.

Justices said Deputy Cascade County Attorney Jennifer Quick did not tell the judge or the defense that the medical records contained evidence clearly favorable to the man’s defense. The records stated that the girl suffered from psychosis, lied because of a mental disorder and may have made and recanted another allegation of sexual abuse.

The court said the prosecution should have disclosed the details from the records to the father so the judge could have ruled whether they were admissible.

“We realize that child abuse is one of the most difficult crimes to prosecute,” Justice Laurie McKinnon wrote in a 5-0 ruling issued on Aug. 24.

McKinnon suggested the prosecution may have been trying to protect the girl from an alleged abuser and the release of deeply personal information about her but said the defendant had a right to due process, adding that justices “are not convinced that this has occurred here.”

Chief appellate defender Chad Wright said the father, who is serving a 50-year prison sentence, will be turned over to the custody of Cascade County as the retrial process begins. County Attorney John Parker and Quick did not return telephone phone messages left Thursday seeking comment.

The girl was 5 years old and living with her maternal grandfather, who was her permanent guardian, when she visited her father in Great Falls in late 2012. Soon after she reported that he had sexually abused her, court records said.

The Associated Press is not naming the father to avoid identifying the child.

The father’s lawyers sought the girl’s medical records because she had been diagnosed with a disorder that made it difficult for her to establish healthy attachments with parents or caregivers. She had lived with her grandfather since she was 3, but court records did not say why.

The father wanted to present expert testimony that a child with that diagnosis might also lie. The court ordered the state to turn over the medical records.

Just before the start of the May 2014 trial, Quick said the state was not comfortable turning over the records until the judge reviewed them. Then the state moved to seal them. District Judge Kenneth Neill granted the state’s motion without reviewing the records, justices said. Neill is now retired.

The record given to the defense contained just one statement about the attachment disorder diagnosis, saying it was mostly likely caused by “early neglect or even possible abuse.”

The only direct evidence against the father was the daughter’s testimony.

“With the significant redactions made by the state in (the girl’s) medical records, the defense was unable to seriously challenge her testimony and the jury had little reason to doubt her memory or truthfulness,” the justices wrote.

The ruling added that “the prosecutor exploited this throughout her closing argument” by saying the girl was in a stable and loving home and there was no evidence she exhibited any symptoms of lying.

The records that the father obtained after the trial said the girl’s living situation was not stable and that she was taking a mood stabilizing medication.

A psychiatrist had considered prescribing the girl an anti-psychotic because she lost contact with reality at times, the records said. A neuropsychologist said the child’s condition was so severe she might need to be treated in a children’s psychiatric hospital and the girl’s grandparents had also complained about her lying, the records said.