We have what’s called an adversarial legal system. Compared to the tribal councils, the dunking chair to try witches, torture to confirm heresy, show trials held by dictators, etc.; it’s a far better system. The adversarial system only works if the prosecuting attorney does their best within the law to gain a conviction (supposedly thus representing the people’s interest) and the defense does their best to defend their client even if they are convinced the client’s guilty as sin.
When it is employed as designed, our adversarial system ensures that, unless a defendant doesn’t want any defense, they will get a vigorous one. That tends to keep innocent people from getting swept up in the legal system and unjustly convicted, something that is a significant risk where cushy jobs as district or states attorney are elective offices and one keeps winning reelection by boasting of how many people they have locked up.
Of course, you are allowed to represent yourself, and if you do so, you can deliberately mount the shoddiest defense imaginable if that’s what you want to do.