They did so by saying that 42 U.S.C. § 1983 (which was passed by Grant to fight the KKK) which was meant to allow people to sue for civil rights violations clearly intends to provide an exception for police officers if they acted in good faith (whatever that means; given that good faith here means enforcing a racist law often with extreme violence). But there's absolutely nothing in the actual law, the text passed by Congress or in the intent of Congress, that supports this reading. You can read the Section 1983 yourself:
> Every person who, under color of any statute, ordinance, regulation, custom, or usage, of any State or Territory or the District of Columbia, subjects, or causes to be subjected, any citizen of the United States or other person within the jurisdiction thereof to the deprivation of any rights, privileges, or immunities secured by the Constitution and laws, shall be liable to the party injured in an action at law, suit in equity, or other proper proceeding for redress, except that in any action brought against a judicial officer for an act or omission taken in such officer’s judicial capacity, injunctive relief shall not be granted unless a declaratory decree was violated or declaratory relief was unavailable. For the purposes of this section, any Act of Congress applicable exclusively to the District of Columbia shall be considered to be a statute of the District of Columbia.
A "judicial officer" by the way is a member of the court / judicial branch, not a police officer.
Because there's no law, qualified immunity is a total mess. Different courts and judges apply it very differently. For some it's simply a blanket defense for essentially any acts.
Ironically, Scalia and Thomas have both written dissents on the other side from the liberal judges at times, pointing out that there is literally no basis in law for qualified immunity and the Court should just drop it entirely.
This isn't just a matter of adjusting the law to clarify the interpretation of Section 1983, although that would help. It also requires a long-term realignment of the Supreme Court who shouldn't be able to wholesale write laws this way. That's not me saying this, that's Scalia in Crawford-El v. Britton "[the Supreme Court] find[s] [itself] engaged...in the essentially legislative activity of crafting a sensible scheme of qualified immunities for the statute we have invented—rather than applying the common law embodied in the statute that Congress wrote".