In this imperfect world, no justice system is perfect.
An adversarial system, with a jury of free men, and state prosecutors who can be voted out of office (or the politicians who appointed them can be voted out of office) is about as fair as you’re going to get. There will always be miscarriages of justice, but fewer than if a gang of tin-pot dictators runs the show and there is no one to oppose them.
You’re exactly right.