For example the navy exists as "force projection" - not coastal protection. Force protection is a foreign policy goal, not a "defense" goal.
The US military is not designed to fight on the US mainland, it's designed to fight on someone else's mainland.
Equally the medicaid budget could be way less. Other countries manage with less (for their entire population) but they dictate pricing, whereas in the US the suppliers dictate pricing. And they expect healthy profit margins at every point.
In general, the govt spends so much because the people charge so much. The govt has enormous negotiating muscle, but dares not flex it least they incur the wrath of "the free market".