I'm no lawfag, but there is a process in place that allows a defendant to withdraw a guilty plea before sentencing takes place. There is a similar process that a judge can use to vacate a defendant's guilty plea.
https://www.nolo.com/legal-encyclopedia/withdrawing-guilty-plea-criminal-case.html