Laws are interpreted by the courts.
Congress might write a law with some expectations.
A well paid accountant and lawyer team might interpret the law differently.
The company employing the team is trying to obey the law, so this isn't illegal tax evasion. But it is tax avoidance, and the use of loopholes may be found to be illegal by the courts, or the law might change to make it illegal.
"Loophole" is just short hand for "unexpected use of law that hasn't been tested by the courts".