Trump’s military campaign in Iran is a sharp turn in tone for a president who has long been critical of open-ended conflicts in the Middle East.