I’ve heard that the answer to this question depends on the situation. Suppose, for example, a US president decides to conspire to poison a city’s water supply to cover-up some administrative abuse or crime and scare and silence citizens. Would this be an offense for which the US military could court martial a US president?
Almost certainly not.
The President is Supreme Commander of the armed forces, but that role is a civilian role. He is not member of the armed forces or subject to the Uniform Code of Military Justice.
Moreover given the President's unfettered power of pardon, it is likely that court-martial proceedings could not proceed against a sitting President, for the same reason that federal criminal proceedings are probably not possible. So if a President was subject to the UCMJ (for some reason) he/she still could not be court-martialled - though this is untested.
Poisoning water would obviously be a State crime, (assault or murder and probably some others too) not a military crime, and so could be tried in state court, probably after impeachment and removal of the President.