As they say, you can beat the rap, but you can't beat the ride.
You sure as hell can get paid for it afterwards.
If the sheriff, DA and judge each thought this was a good idea, it's fair for the voters who hired them to take the hit.
Typically the sheriff is always elected, the DA almost always elected, and for the judges it depends, but if they aren’t elected they are appointed by elected officials.
The other thing to remember is that the US judicial system varies tremendously by state. No two states are the same so there is no easy way to summarize it.
Even if they're not, they're local enough positions that electeds have significant--if not final--say over their appointment.