If the whole community believes X is not a crime and willing to nullify the law as juries, certainly they will elect a prosecutor who thinks the same.
That's a drastic oversimplification. For one counterexample, consider a prosecutor who believes x but also y. The community agrees on x but not y and consider that a dealbreaker, so the prosecutor is not elected. And this doesn't include issues such as ease of voting and gerrymandering.
They will also elect legislators that will remove such laws.
Or subject to recall. Which is what just happened to San Francisco DA Chesa Boudin.
After the cops decided not to arrest, then blame Boudin for not prosecuting. Cops just hanging out watching the crimes.
Let's not turn it into a whole Boudin debate. He was recalled, which indicates some level of voter discontent with how he operated. I personally voted against recall, but it is what it is.