Presumably, he only did that because he thought the case would be in the hands of a jury anyway, so it didn’t matter as much if he antagonized the judge. Whoops.
You're giving him too much credit. When analyzing his behavior, it always helps to think like a first grader. The judge was mean to him, so he's being meaner back. It's as simple as that.