If you go back to colonial times, you find that the original “red states” were those who believed in state’s rights, state nullification and that states could cecede from the union. The Civil War was as much about that as slavery. Jefferson, Madison and others debated the two views. The Civil War settled the issue by declaring that the union could not be dissolved ans was not so much a confederacy as a dual system of government.
That war forced the seceded states back into the union, but didn't declare that state secession was illegal--that would be a job for the Supreme Court or for Congress to make a clarifying law.
And in the case of Texas--and Virginia(?)--forcibly reuniting the state was illegal. Texas joined the union with an agreement that the state be able to secede and become fully independent again if that was what the state chose.