It does but selective quotes are misleading, sometimes very misleading, as this is.
The actual oath is:- “I, _____, do solemnly swear (or affirm) that I will support and defend the Constitution of the United States against all enemies, foreign and domestic; that I will bear true faith and allegiance to the same; and that I will obey the orders of the President of the United States and the orders of the officers appointed over me, according to regulations and the Uniform Code of Military Justice.”
So allegiance to the constitution comes first.
You would need to study and understand what the precise meaning of those regulations and code is, but in essence it means nothing illegal is permissible. You can read about it here:-
The call from Democratic veterans in Congress highlights the federal law that dictates the conduct of members of the military.
abcnews.go.com