We could make our only law and norm be just “do the right thing”. (Or, maybe, the most economically efficient thing.) Then when someone was accused of acting badly, the relevant judge or jury would consider if their actions were unusually bad, all things considered. But this seems a quite noisy, expensive, and corruptible system So we usually instead try to agree ahead of time on more specific local norms and laws, to give us each a better idea of what is expected of us, and to better hold our judges and juries accountable.
In this usual sort of system, we often encounter cases where our norms and laws seem to some of us to push for something other than the most right acts. We try to limit such cases by adding vagueness and other kinds of flexibility to our norms and laws. After all, the optimal level of precision in our rules, and discretion in our rulings, is probably not at the all-precision-no-discretion extreme. At that optimum, the cost of the extra corruption induced by that extra discretion is more than paid for by an extra ability to promote doing the right thing.
Even so, we still end up with cases where the “letter” of the law, i.e., the outcome our current rules push for most simply and directly, seems in conflict with the “spirit” of the law, i.e., what would most push us all to do the right things. When specific cases like this arise, people sometimes argue for case-specific adjustments to our precision and discretion tradeoff. They want us to spend an unusual amount of our judge-discretion budget to push for an unusually-big deviation from our usual law/norm concept. That is, they recommend that, in this particular case, that we go more with the spirit, not the letter, of our law/norms.
For example, like Billions, the TV show Suits is good competency porn. In Suits, characters get rich and prestigious via their amazing abilities to wield the letter of the law to favor they and their clients. But in episode S3E12, two of the main characters face situations where the letter of the law will clearly go against them. However, they convince a judge and an associate to see them as unusual cases, due to an unusually clear view that they are especially good people, so ruling in their favor is an especially good choice. After which they go back to getting rich wielding the letter of the law.
Not finding much in the academic literature, I just did some Twitter/X polls to elicit attitudes re letter vs. spirit of law/norm choices. These show very strong support for using the spirit of the law. Even though real legal judges are quite reluctant to admit that any of their rulings deviate from accepted precedent and existing rules, 36% of my respondents say that they instead want the spirit of law to determine official court rulings over half of the time, relative to the letter of the law.
Furthermore, respondents want the spirit followed more the less formal or distant is the legal context. Relative to the letter of the law, we want the spirit followed least for formal law, a bit more for org rules, more when we judge social norm violations as third parties, and the most when we judge social norm violations against ourselves. In that last case, 77% want the spirit followed over half the time.
This urge to use the spirit over the letter of the law (or norms) is mostly an urge to excuse people who violate the letter but not spirit, and much less an urge to punish someone who violates the spirit but not the letter of the law (or norms). And we are far more inclined to excuse people who we see as better and more valuable to society.
Finally, note that when norms or laws are expressed in terms of social miracle concepts, applying the “letter” of those concepts will mostly find behavior to be inadequate, failing to meet our near impossible standards. Thus we must in fact be usually applying the spirit of such norms to a large extent. Which gives us a lot of discretion to hurt each other, which may bind us more together.
The above results suggest wide approval for excusing particular people in particular cases from their literal violations of our laws and norms. At least when we value those people highly. No matter what our general rules, we want the option to pressure judges, juries, and other social evaluators to excuse our favored targets on the basis of hard-to-evaluate case-specific judgments of the overall value of they or their particular actions. But for others, we want our rules imposed more strictly and reliably. Law for thee but not for me?
Of course, it is better if the spirit of the law could be applied. But you seem to be making the assumption that giving judges more discretion would result in the spirit of the law being applied. Very dubious. More discretion leads to more corruption and bias. In the limit of increasing discretion, you have lawmen who "are the law" and do whatever they want. That's little different from being ruled by a gang or warlord. Which does not usually turn out well for the people.
Sure, everyone wants the spirit of the law -- so long as they agree. It's like having a benevolent dictator. It takes a knowledge of history to see how these things fail in the long run.
Not so long ago US judges sentenced black people to longer prison sentences for the same crime, because even though the law can't outright say that black people are more dangerous, everyone knows thats the spirit of the law, right?