Tax avoidance is legal; tax evasion is not. The US tax code is so complicated that probably no one understands all of it. It is laced with special interest loopholes that may be interpreted in more than one way. When Congress writes the law, it usually instructs the IRS to interpret and apply the law in accordance with the laws already on the books and as rationally as it can. That provides work for private tax lawyers and specialist tax accountants.
While Mitt was at Bain, it was his job to reduce the taxes paid by the companies that Bain bought and sold. It is the responsiblity of a CEO to maximize profits for shareholders by minimizing taxes paid. Mitt probably decided to use some of the tax avoidance schemes he learned about and apply them to his own income. Many of those tax avoidance schemes are available only to the rich. One rule for them, another rule for the 99%.
It is probable that Mitt’s tax avoidance would resemble tax evasion to many voters if his tax returns were released. I think that is the real reason for Mitt’s secrecy.