It wasn’t illegal. The 1869 SCOTUS could hardly be deemed honest precedent on the matter. In 1789 not one state thought it was entering a “roach motel”. The “Perpetual Union” language was in the Articles of Confederation and it was not included in the Constitution.
Cheif Justice Roger Taney explained why succession is unconstitutional in a memorandum on 1 February 1861.
"The South contends that a state has a constitutional right to secede from the Union formed with her sister states. In this I submit the South errs. No power or right is constitutional but what can be exercised in a form or mode provided in the constitution for its exercise. Secession is therefore not constitutional, but revolutionary; and is only morally competent, like war, upon failure of justice."
In other words, there is no way for the concept of unilateral secession to be exercised under the US Constitution, for no mode or form of such is provided in that document
This is the Chief Justice Justice of the United States BEFORE the Civil War even started.