BILLINGS, Mon. -- A former teacher sent to prison for 30 days for raping a student is set to return to court Friday because the sentence may have been illegal, but the move has failed to quiet criticisms of the judge overseeing the case.

District Judge G. Todd Baugh said Tuesday that state law appears to require a two-year mandatory minimum prison term for Stacey Rambold, 54, of Billings.

"In the Court's opinion, imposing a sentence which suspends more than the mandatory minimum would be an illegal sentence," Baugh wrote.

But that did little to sway Baugh's critics, including hundreds of protesters who rallied outside the Yellowstone County Courthouse last week to call for the judge's resignation.

"I wish the judge had been thoughtful enough to get it right the first time," said Eran Thompson with Not in Our Town, a Billings group that promotes diversity and works against hate crimes.

"The judge cannot take back the words he said when he blamed the victim. As far as we're concerned, Judge Baugh has lost the trust of this community," Thompson said.

Yellowstone County Attorney Scott Twito said Baugh may lack authority to impose a longer sentence at this point. That's because state law says an illegal sentence must be handled through the appeal process.

Rambold was sentenced last week to 15 years with all but 31 days suspended and a one-day credit given for time-served. He has begun serving his monthlong term at the state prison in Deer Lodge.

The judge has faced widespread condemnation from activists, elected officials and others for the sentence and for saying Rambold's 14-year-old victim, Cherise Moralez, was "older than her chronological age" and asserting that she had some control over her months-long relationship with Rambold.

The judge later apologized for his comments. Those who have called for him to resign said an apology is not enough.

Moralez killed herself before Rambold's case came to trial. That left prosecutors without their main witness and led them to strike a deal with Rambold that allowed him to avoid prison until he violated the terms of his court-ordered release.

Court records show that the sentence Baugh handed down was in line with what Rambold had requested.

Prosecutors, who sought 20 years prison with 10 years suspended for Rambold, have described his actions with Moralez as "the ultimate violation" of the trust she had placed in him as a teacher.

Court documents show that Rambold and Moralez had three sexual encounters -- once at school, once in his car and a third time at his home. The relationship was still going on when authorities were notified in 2008 after Moralez confided in her youth counsellor, the court documents state.

"Law enforcement intervention ended the relationship, not the defendant," prosecutors said in an Aug. 23 sentencing memorandum.

Twito said last week that he was considering an appeal, and cited the two-year mandatory minimum requirement as grounds. He said he planned to be in Baugh's courtroom Friday but was unsure how the hearing might play out under the law.

"I've done this a long time and I'm in an area I have not been in before," said Twito, now in his 16th year as a prosecutor.

If his reading of the law stands up, that could give the defendant the advantage in Friday's hearing.

Twito said members of his office, along with Rambold's defence attorney, Jay Lansing, met informally with Baugh last week to discuss the case.

Baugh said in Tuesday's order that the defendant's pre-sentencing memorandum claimed the minimum mandatory for sexual intercourse without consent was 30 days, and the state did not object until after the sentence had been handed down.

Lansing could not be immediately reached for comment.

Twito said his office will continue to pursue a possible appeal if the sentence remains unchanged. A final decision would be made in conjunction with the appellate division of the Montana attorney general's office.

Baugh, 71, was first elected to the bench in 1984 and has been re-elected every six years since without an opponent. He's up for re-election in 2014.

Baugh said in response to the criticism that followed his remarks that Rambold's sentence was based on the defendant's violation of an earlier deal he made with prosecutors, rather than the original crime. He also claimed that his remarks about Moralez were "irrelevant" and did not factor into his sentence.