I think you are a bit confused.
Let me clarify.
Judge obligated to tell you about immigration consequences ONLY when you go for a plea. In this case no trial would happen.
One can change his plead from Not guilty to guilty in teh middle of trial
I think you are a bit confused.
Defendant can revoke his original plea in case judge didnt tell him about immigration consequences.