I think I know what Mattis is trying to do by accepting this position, and it is not because he supports Mr. Trump: Mattis is sacrificing himself.
He knows that this will not end well, but he’s doing it in order to preserve what he can of the military for the long-term, despite Trump. And he knows that he scares Trump. And so, he is essentially offering himself up as a shield. He knows his history, and he believes in civil control of the military. But in this case, and I suspect in only such a unique case as that of Trump, Mattis may have reached the conclusion that the nation’s armed forces need protection from their own commander.
From: Why Donald Trump Chose James Mattis – A Military Veteran’s Perspective