The court rules when the matter comes before them. In this case it happened to be 1869.
Secession happened well before.
When it happened is irrelevant. It's when the court took the matter under consideration. As it happened it was after the rebellion was over.
You cant say see the courts said it was illegal after the fact...
Every decision handed down by the court is after the fact. Courts cannot rule on something that hasn't happened.
Your contention is that secession was illegal. It is now, but it was not in 1861.
The states were united but separate entities. They claimed the right to leave the union.
I would contend they were not wrong. And they certainly had arguments supporting their position, from Jefferson to Madison and the understandings of the states themselves.