My friend always appears in court after getting speeding tickets because it is apparently more costly for the court to pay for the session and the officer's time than what they will get from a ticket, so they usually dismiss it to save money. Sometimes the officers don't even show up. He has told me it works every time.
If everybody would choose to appear in court like your friend does, perhaps this law that most people don't follow would actually get changed. Instead most people just pay the ticket and continue to allow the law to "work" as it is.
In criminal court? I can't think of any jurisdiction that charges a fee for pleading not guilty, going to trial, and being convicted.
In civil court outside the US, the loser pays attorney's fees. I don't know about court fees, since those are usually relatively tiny compared to attorney's fees.