Sometimes, the wording of a law or contract is vague and imprecise, and it allows people to abuse it, but doing so goes against the spirit of the law or the contract when it was written, or in other words the intention the people who wrote the law or contract. Is there a word for this?
This is known as a loophole.
There is a principle in American jurisprudence that if a law is too vague, it is not valid. Similarly, if a contract allows more than one reasonable interpretation, the party who wrote the contract does not get to decide which interpretation(s) will be used. Instead, the other party gets to choose.
Consider the etymology of loophole:
also loop-hole, mid-15c., from hole (n.). + Middle English loupe "narrow window, slit-opening in a wall" for protection of archers while shooting, or for light and ventilation (c. 1300), which, along with Medieval Latin loupa, lobia probably is a specialized word from a continental Germanic source, such as Middle Dutch lupen "to watch, peer." Figurative sense of "outlet, means of escape" is from 1660s.
Loopholes are placed intentionally for avoiding certain provisions, usually for benefit of special interest groups or other political donors. Those who take advantage of loopholes are using the law as it was intended, at least on some level. The term can also be problematic because people sometimes (especially in political contexts) disparage aspects of even precise laws that they simply dislike as loopholes, e.g., the “gun show loophole” or the “mortgage interest loophole,” and the discussion degrades into an argument over whether it is truly a loophole or part of the intent.
The scenario from your question involves twisting or perverting the law into saying something that it does not say. Read on for more more accurate descriptions.
Applied to rhetoric in general and not just legal argument is sophistry:
The use of clever but false arguments, especially with the intention of deceiving.
‘trying to argue that I had benefited in any way from the disaster was pure sophistry’
Another possibility is legalism:
Excessive adherence to law or formula.
Realize that the term can have religious connotations, as described in the second sense of the linked definition.
For a more cynical and even inflammatory characterization, Lavrentiy Beria was head of Stalin’s secret police and is said to have boasted, “Show me the man, and I’ll show you the crime.” In other words, he believed he could manipulate the law to find any person guilty. Crisis Magazine ran a piece called Beware the Beria Method (emphasis added). Note that this is not in common usage.
In Federalist No. 41, James Madison rejected the claim that the then-proposed U.S. constitution conferred to the new federal government any power that might be alleged to benefit the general welfare with (emphasis added)
No stronger proof could be given of the distress under which these writers labor for objections, than their stooping to such a misconstruction.
Finally, someone seeking to abuse law or contract terms is said to use a strained interpretation, an overly literal interpretation, or a tortured interpretation. A less formal and broader way to state it is the person is out in left field or, to avoid the personal attack, that the interpretation came out of left field.
A literal interpretation. This is not always a loophole.
There is a lot of poorly crafted legislation about.
Suppose we define a motor vehicle as any vehicle not powered by a human or an animal. Then any unpowered vehicle is a motor vehicle. Powered is not the same as "propelled by". Weight is not the same as mass. An AAV is not remotely piloted, nor a drone, and need not be unmanned.
A person going naked may be arrested for being improperly clothed. To be convicted, the prosecution must produce the alleged clothing.
This is not the same as "Ultra Vires" where no (delegated) power exists to enact a law as written.
There are rules of statutory interpretation, generally a court will follow the letter of the law. A tribunal may consider the "intent" of the lawmaker.
Remember, a court of law is not the street. It was not Bill Clinton that maintained a certain act was not "sex", it was the law of the land in failing to enumerate the act.
Right now, in the US, I can walk into a shop and buy a ghost gun by using my own hand to switch on a milling machine for part of that gun that I fit myself, and I have satisfied the law requiring that weapon to be unfinished to a degree.
Where I live it is illegal to buy sausages after midday on Saturday. But wrap them in pairs in cling wrap and they are "Barbecue Packs".
IANAL - talk to one if you need to.