WEST PALM BEACH, Fla.—President Donald Trump’s decision to order military strikes in Syria sets his presidency on a new and unpredictable course that is likely to shape his time in office.

Faced with his first major foreign-policy test—a moment that confronts every new president—Mr. Trump demonstrated a comfort with military action and a flexibility in approach that saw him change course not only on comments he made in the campaign but also on his policy toward Syria in just 48 hours after seeing gruesome photographic evidence...