In a rare legal situation, a 25-year-old man was sentenced to life in prison Thursday after he pleaded guilty to raping four Roswell women from 2014 to 2016 — then changed his mind and will stand trial.

Errol Alex Martinez “pleaded guilty to the entire indictment and was sentenced to life in prison with the possibility of parole,” Fulton County District Attorney spokesman Chris Hopper said.

“However, Martinez discussed the sentence with his lawyer and decided to withdraw his plea. The case will be set for motions and will proceed to trial.”

No trial date has been set.

Such a withdrawal is “very rare,” Atlanta defense attorney Ashleigh Merchant told AJC.com. “It’s completely up to the judge.

“Most judges don’t do it.”

Merchant said some judges will allow defendants a few minutes after they pronounce sentence to withdraw their plea.

“This is most often in situations where the sentence is what is called non-negotiated, which means that the defendant and the state have not reached an agreement on the sentence but instead left the sentence up to the judge to decide,” she said.

Martinez ambushed all four women and broke into the homes of three of the victims, Fulton County District Attorney Paul Howard said in a statement before the hearing.

“According to the indictment, the defendant is alleged to have violently assaulted and threatened all of the women into submission before vaginally and anally raping the victims,” Howard said.

He’s also facing a rape charge in Gwinnett County under a separate indictment.

RELATED: Man faces rape charges in Roswell, Norcross

Roswell police officer Lisa Holland said “(Martinez) had been into so many homes that he can’t remember them all.” She also told Channel 2 Action News he attacked the women in bizarre ways to make their stories seem outlandish.

Martinez’s victims were single women age 46 to 60, Holland told AJC.com.

In other news:

Police are searching for two men and a woman in the shooting.