Last summer, Mr. Mattis sharply criticized Mr. Trump’s proposed ban on Muslim immigration as a move that was “causing us great damage right now, and it’s sending shock waves through the international system.” Customs and Border Protection officers were also caught unaware.