It's complicated because the District Attorney is usually responsible for seeing cases against police and deciding to bring charges but they rely on having a good relationship with the police.
The high profile stuff you see on the news are the hard cases. Most of the time the instances where people say they got away with something are very biased takes that leave out a lot of context rather than a successful cover-up, though both do happen.
People talk about qualified immunity like it's a personal shield for police but it's much more nuanced than you'll read about most places. Qualified immunity just says that the individual police officer has immunity from prosecution or liability in cases where they genuinely believe they are doing their job correctly.
The absolutely absurd wrinkle is: courts often skip the rights question entirely. Since Pearson v. Callahan (2009), they can decide either "prong" first, but many decide only that the right wasn't "clearly established". As such, the underlying violation goes unruled on and precedent is never established.
Rarely, courts hold the conduct so obviously unconstitutional that no precedent is needed and that QI doesn't apply. Those rulings are rare and often reversed on appeal, including by the Supreme Court. Even if they survive appeal to the circuit level, courts are under no obligation to "listen" to a ruling from a different circuit (it's how "circuit splits" happen).
Why does it apply only to cops? If I'm drivind at 60mph in a 50mph zone but I genuinely believe the max speed is 60mph, do I get a fine?