You can thank your peers for that.
Let's face it. The people in the legal system wouldn't feel compelled to specify a dress code if a number of people hadn't shown up looking like slobs. So, instead of relying on people to dress appropriately (which they can't these days, it seems), they impose a dress code. The people working for the courts are people, too - it's not like they sit around thinking of ways to eff with you.
I forgot to give another example - it might not be the defendant to think about, it might be the people on the other side. Perhaps someone killed someone's son or daughter, and the family is hoping to see them get convicted. Imagine their stress if the jury is sitting around in tank tops and chewing gum the whole time. Btw, I'm not saying that would be you.
I'm saying that's probably an example of what the court is trying to avoid.