I would say Respect born out of Fear, on Trump's part.
QFT. Even Trump, with as much ego as he has, must recognize that Mattis has the support of damned near everyone who is wearing, or who has worn, a uniform in defense of this nation, along with their friends and family. Keeping Mattis means, in large part, keeping those votes on his side.
You know, I always pictured Mattis as the kind of General who would be willing to roll up his sleeves and get dirty next to his Marines if that what was needed. I picture him leading from the front, not issuing commands from an air conditioned office like a REMF. The kind of officer I respected and tried to emulate when I was wearing a uniform.