The colonies tried and succeeded. The Confederates tried and failed.
That is beside the point. You just claimed that unilateral secession is illegal. But if it was ok for the colonies, it was ok for the CSA.