You might have seen the somewhat humorous incident where NFL wide receiver
Chad Johnson, formerly known as Chad Ochocinco, celebrated a favorable
outcome in court by patting his attorney on the rear. The judge didn't
think this was very funny, and decided to withdraw approval of the plea
agreement and sent Johnson to jail.
This led many to ask, "Can the judge do that?" The short answer
is yes. An agreement that is worked out between the defense attorney and
the prosecutor is actually just a proposed plea agreement which is subject
to the judge’s approval.
Usually, the decision to dismiss or amend charges is up to the prosecutor,
but the sentencing is ultimately up to the judge. Sometimes this works
in favor of the defense, since a judge can give a lighter sentence than
the prosecutor wants. But, as in the case of Chad Johnson, sometimes a
judge won't approve of a deal agreed upon by the defense and the prosecutor.
So, if you're not sure whether or not the judge is going to appreciate
your particular style of celebrating or congratulating, it is best to
wait until you are outside the courtroom.