Speaking as someone with 20 years in uniform and as a War College grad (if only by correspondence) . . . the military ironically has this wired more than any other institution in the Federal government. The reason the military gets drawn into so much of US foreign policy is not because of a fetish for blowing things up. It's because it's the only institution where formalized planning is a thing, the only one where feats of large-scale logistics are par for the course, and the only one where "I'm not going there because I might get hurt" isn't a valid excuse.
As an example, one of the best ways for distributing aid after a natural disaster is an amphibious task force, because you can send the same Marines in to distribute aid that you would to take territory. And going into relatively unprepared areas and setting up infrastructure for follow-on forces is basically their bit either way.
The problem comes in because military force is never the complete solution in and of itself outside of something like what's currently happening in Ukraine. And when you involve all the other agencies plus scads of glory-seeking politicians, it's hard to keep things from becoming a shitshow.