An Indonesian court has approved the legal appeal of a Sumatran teenager who was repeatedly raped by her brother and then jailed for having an illegal abortion.

The decision from the high court in Jambi, a province in east Sumatra, will clear the way for the 15-year-old girl to be released in coming days.

The court issued its decision on Monday, ruling that while the teenager did undergo an illegal abortion, the circumstances warranted her release.

“The panel of judges stated that [the defendant] was proven to have had an abortion but it was done under forced circumstances,” said Jambi high court spokesperson Hasoloan Sianturi.

Her lawyer, Damai Idianto, told the Guardian he was “very happy” his client had been cleared of the charges.

The case has incensed women’s and rights activists across Indonesia, who decried her original six-month jail term as a legal travesty.

Ida Zubaidah from Beranda Perempuan, a women’s organisation in Jambi, applauded the decision, but called for investigators to drop a case against the victim’s mother, who is being detained on suspicion that she helped her daughter illegally terminate the pregnancy.

“We appreciate the solidarity and support in this case and that the judges have responded to that by giving justice to the victim,” said Zubaidah. “But now efforts must turn to trauma healing and efforts to release her mother.”

Abortion is illegal in Indonesia, with the exception of extraordinary cases such as rape, but even then it is only allowed at the earliest stage. Forensic tests on the foetus, which was discovered half buried near the victim’s house this May, revealed the teenager had been seven months pregnant.

The 15-year-old told the first court trial she had given birth alone in her room after drinking a herbal mixture of turmeric and salt to treat her stomach pains.

Identified only by her initials in the local press, she was initially jailed in the same prison as her brother, who was sentenced to two years for sexually assaulting a minor. She was moved to a safe house following the outcry over her case.

As of Tuesday the teenager was still in the safe house, where she was receiving psychological assistance and Koranic instruction. Following the court’s decision, women’s activists are working with social services to arrange for her to remain in the city and continue her high school education.

Helfi Rachmawati, from the consortium of women’s NGOs in Jambi, said the teenager was unwilling to return to her small village, several hours from Jambi city. She was suffering from trauma and depression, and anxious about being separated from her mother.