The Chain of Command
The US Constitution explicitly names The President as the 'Commander-in-Chief" of the armed forces of The United States . . .ALL of the armed forces. It further specifies that the
congress alone has the power to declare war. These two provisions are intended to subordinate all military commanders to the authority of elected civilian officials. In current practice, the President usually consults the Secretary of State and the Secretary of Defense when exercising his command authority over the military. Congress often authorizes use of force to the President in lieu of formally declaring war. In all cases, the authority to command the military forces of the United States to act or stand down ultimately resides with the President alone.
In current practice, The Joint Chiefs of Staff are established by statute law as an advisory body to the Sec-Def. The chain of command for military operations does not involve any of the Joint Chiefs or any of their subordinate staff. Rather, the chain of command coms directly from the president, through the Sec-Def to the undersecretaries of each branch of service and then to the regional commanders of their respective services.
General Miley has by his own admission exceeded his statutory authority, gone outside the established chain of command and undermined or even usurped the authority of a sitting president.
General Miley's doubts about the ability of a president to act rationally is a matter to be taken up by elected civilian officials; the Vice President and Cabinet Secretaries via the provisions of the 25th Amendment. Any such act on the part of any military official constitutes an unlawful act; essentially an attempted coupe.
But don't take my word fot it. /thuis information is all available online with a few clicks.