Legal Authority
The All Writs Act is part of the statutory authorization for the civil contempt power as is 28 U.S.C. § 1826 (regarding compelling testimony from recalcitrant witnesses) and governing enforcement of court orders in general.
Criminal contempt proceedings are governed by 18 U.S.C. §§ 401-402. See, e.g., here.
But, the civil contempt process is not spelled out in detail in the Federal Rules of Civil Procedure (as it is in most state courts), and is largely a result of the inherent powers of the judicial branch in the federal system as interpreted in light of English tradition prior to the Declaration of Independence and federal court case law.
Judges also have great power to authorize the seizure of assets to satisfy money judgments in a process largely independent of the President.
Federal Judges Are Not To Be Underestimated
It also bears making an observation about federal judges.
A federal judge unlike a judge in almost every other country in the world even at the highest level, is an extremely well politically connected political appointee who secured his or her position usually only after having had a very successful career as a lawyer, often followed by an equally successful career as a state court judge. They are "highly effective people" who know not just the written law but the unwritten rules of how the world works who are often not afraid to use that knowledge. They routinely adjudicate political struggles between powerful factions. They do not have the slightest doubts about their own personal authority. They have had far more time to learn the ropes and develop experience than any elected or politically appointed person in the executive branch.
Collectively, federal judges are jealous of the powers of the judiciary as a whole and are incredibly savvy and competent. Their command of power play tactics in U.S. politics, and their collective intelligence rivals or exceeds that of the most competent members of Congress, senior executive branch officials, or military officers. Their only real rivals in terms of raw human capital in the world are the senior public law lawyers in the French Council of State.
They are not to be underestimated.
How Easy Is It To Control The Executive Branch?
For example, the executive branch controls law enforcement and the
military. That would seem to indicate that if desired the executive
branch can do what it wants and only can only be held to account by an
uprising of the people via voting and if that fails then other
measures.
In an extreme case lets pose this question. Executive defies court
orders that were validated up to the supreme court. Legislative branch
impeaches the president. The executive branch remains loyal to the
president and refuses to remove him from office.
The propositions in bold are not as obvious as they seem.
The United States does not have a unified executive branch, due both to federalism and the way that the executive branch at the federal level is structured.
Also, the military's duty to obey the commander in chief is limited by each soldier's duty to disobey an unlawful order, a conflict about which active duty military personnel in the U.S. military receive considerable indoctrination.
In the case of an impeachment, there is also a clearly recognized successor who has "the wind at his back" due to his legitimacy in organizing support relative to the President and the support of two-thirds of the U.S. Senate and a majority of the U.S. House of Representatives who are extremely well connected politically as a collective group.
The Divided Executive
Of the roughly 18 million government employees in the United States, only 1 million or so a civilian non-postal service employees. About 15 million are state and local government employees who don't report to the President. About 1.5 million are active duty military. The postal service, which makes up on the order of half a million employees (it was twice that when I was a kid) is not in the direct chain of command from the President who appoints people to a Board of Directors who appoint a CEO who runs the USPS.
Something like 20% of the other million civilian non-postal employees in the federal government are also in independent agencies who aren't subject to the direct line authority in a chain of command from the President.
The President also doesn't have direct authority to fire federal employees who are members of the civil service system (most of whom are also unionized and inclined by nature to resist suspicious action of the President). Pretty much, the President can only fire political appointees (of which the are roughly 5,000 in round numbers), without going through the civil service system. Ignoring the President is less likely to get you fired by the civil service system than ignoring a U.S. Supreme Court order. A lot of federal government civil service employees are also ultimately quietly idealists who when push comes to shove may not follow a clearly illegal Presidential directive as determined by the federal courts.
The Difficulty Of Uniting The Military To Defy The Courts
The military's support of the President, even though it is in the President's direct line of command and control, isn't so reliable either.
If you defy the President and his faction wins, you could be executed in a court-martial. If you defy the President and his faction loses, you could be indicted for committing a crime by obeying an unlawful order, or even treason, and face death or a long term of imprisonment following a trial in a civilian criminal court or a court-martial of the winning faction. The side the people take depends to a great extent on how consistently they think that one side or the other is to win, and the smart move, if you can manage it, is to avoid taking any action that clearly shows which faction you sided with in the struggle in a passive-aggressive fashion.
The Department of Defense and Coast Guard are so sprawling that organizing defiance to federal court orders, even when the encouragement of the President as commander in chief, is a non-trivial matter. There are hundreds of generals and admirals who have to fall in line for that to happen.
The U.S. Navy and the U.S. Air Force are ill suited to holding domestic territory. The U.S. Army is close to the lowest number of soldiers it has had since before World War II, and the U.S. Army has a larger share of soldiers who are not "front line" riflemen (e.g. diesel mechanics, computer operators, medics) than at any other time in its history. And, of course, lots of military personnel at any given time are abroad or afloat where they wouldn't play a role in the power struggle.
In order to get the mass of soldiers needed to hold the country by force in defiance of judicial orders, you need to mobilize the Army and Marine reserves and to activate the Army National Guard who may refuse to do so if their state Governor concludes that the President's mobilization order is an unlawful order designed to circumvent a court ruling.
Unless the President can almost unanimously convince all of the myriad components of the military and law enforcement that his defiance of the U.S. Supreme Court or a Congressional impeachment is proper, he faces the prospects of a bloody military struggle to retain control.
In a great many countries less stable than the United States politically, in a crisis of legitimacy and control, some factions of law enforcement and the military remain loyal to the usurper and others do not and they go to war with each other.
For example, this happened in the latest coup attempt in Turkey.
Conclusion
So, any President who wants to attempt to defy the Courts needs to have the overwhelming near unanimous support of the people with guns and the people whose support is needed to rule at both the federal and state and local level, which is not an easy thing to manage.