Anne Sacoolas is somewhat more nuanced than that, mostly because Diplomatic Immunity is a strange necessity for functional alliances.
The underlying gist is that people important to the government or possessing sensitive knowledge are immune to prosecution from allies to prevent prosecution being a viable method of coercing information from government officials. Ie the US cannot charge a UK ambassador, because that ambassador may be tempted to leak secrets in exchange for leniency.
The same typically goes for family members for the same reason.
In this case Sacoolas had done undercover work for the CIA at some point, so likely had knowledge the State Department did not want leaked. Her husband was active in the CIA and likely also had similar knowledge.
The same is true in reverse. You can look up the court cases, the US has had to drop several cases due to diplomatic immunity.
There is an element of might makes right to diplomatic immunity because there is no real higher power to enforce it. If a country is willing to weather the political fallout (and reciprocal loss of diplomatic immunity), potential hostile action, and can get their hands on the perpetrator, they’re free to ignore diplomatic immunity.
In practice, diplomatic immunity is almost always respected, even when it could probably be ignored, because of onlookers. If the US ignores eg Kenya’s diplomatic immunity (who they can likely afford to piss off), it might worry the UK who the US does not want to piss off.
Diplomatic immunity is very, very rarely ignored, but is waived with some regularity. The US is particularly liberal with granting diplomatic immunity, though, and more reluctant to waive it than most countries.