I call your attention to Article III, Section 3 of the US Constitution. "Treason against the United States, shall consist only in levying war against them, or in adhering to their enemies, giving them aid and comfort."
Let's use Robert E. Lee as a textbook case of treason. Lee graduated from the United States Military Academy (not the Virginia Military Institute). He was commissioned an officer in the Regular Army of the United States (not the Virginia militia). To obtain that commission, Lee had to swear the following oath: "I, _____, appointed a _____ in the Army of the United States, do solemnly swear, or affirm, that I will bear true allegiance to the United States of America, and that I will serve them honestly and faithfully against all their enemies or opposers whatsoever, and observe and obey the orders of the President of the United States, and the orders of the officers appointed over me, according to the rules and articles for the government of the Armies of the United States."
There is no wiggle room in that oath for allegiance to one's state superseding allegiance to the federal government. Lee was a traitor; he renounced his duty to his country and he deserves to be lighted down in history with his fellow turncoat, Benedict Arnold.