See Article II of the Constitution which places the President as CIC over all military forces nationally, and of state militias. Connect this with the Insurrection Act, particularly Section 253 which allows the President to deploy military or state guard troops when the legislature and governors of states with civil unrest and insurrections refuse to enforce federal laws and keep the peace.