Mr. Mattis’s resignation letter was the sharpest, and most public, protest from inside the Trump administration over the president’s rejection of the alliances and relationships that have underpinned American security since the end of World War II.