You can't.
Because there's a massive string of major and minor crimes that are instigated by an unknown person or group. The people committing the crimes are arrested, but the instigator(s) aren't due to the AI not being able to detect them, as they aren't committing any crimes themselves.
Eventually a detective discovers this conspiracy against the AI, but can't do anything about it, since it's somehow not a crime. The detective might eventually convince lawmakers to write this law, the instigator(s) get arrested, and a lot of "innocent" people are released. Thus continuing the dystopian future.
Or the idea of this real conspiracy somehow gets made public and puts the AI's decisions into controversy, as intended, and the whole thing falls apart as the AI starts instructing mass arrests as people start protesting, which "of course" turn violent.
Regardless of how it turns out, the instigator could be found out to be the maker of the AI, police that want the AI to end, or even high ranking police that want to keep their purpose/power, but unintentionally their plan is found out.
Edit:
I just had a thought.
You could have the detective go around fighting to stop the instigators in the first story/book/whatever, while the detective eventually realizes the AI does need to go and feels bad for stopping the resistance/meddling.
In the sequel, you can show the damaging effects the AI had after it was allowed to run "unchecked", so the same detective starts the resistance (again), using the same or similar tactics as before, but in ways that make it absolutely obvious that the AI is wasting money, completely wrong, and draconian. I envision the AI being repurposed to find people employment they love and excel at to make society better, instead of being completely dismantled. But I'm a bit of a romantic, and I don't really like dystopian stories. ;-)
I realize this edit doesn't exactly gel 100% with my original Answer, but it's all just suggestions anyway. Hopefully something I said helps you out.