Most likely scenario:
Mattis was clean in early career but as the cabal gained control, he found himself surrounded.
He witnessed or learned “too much” and was given the ultimatum to get his hands dirty and cooperate or face consequences.
He accepted bribes so the cabal could hold it over him as black mail. He was a passive cooperator with the cabal from then on, but likely not in the inner circle properly.
He gladly flipped, in secret, for Trump. He is stepping down both to testify and because his role in the position has been served to completion.
He is no angel, but he is likely now cooperating with the white hats.