My question involves criminal law for the state of: California

I was charged with contempt of court for wearing a shirt to court that said f*** the police. I was asked to turn the shirt inside out first but I told them I had the right to refuse as the shirt is my property and it is my body. What exactly is contempt of court and how can I beat the charge? Why would the court even care that i wore the shirt in the first place