If a prosecution is legally justified, a court can’t do anything about it. At best, you could hope for jury nullification (but the rules of evidence might keep the jury from ever learning the morally-exculpatory evidence), or failing that, lenient sentencing.
This is what I was alluding to. Historically judges have had a lot of leeway when it comes to sentencing, and, having heard all the details of the case, they are in the best position to decide the defendant's fate. (For what it's worth, I disagree with mandatory minimum sentencing laws.)
I’d much rather a police officer be able to make the call to not pursue something than regularly have people stand trial for trifles. If you don’t give the discretion to cops or prosecutors, that is the alternative.