Yes, we all remember the time Hungary and Czechoslovakia behaved illegally. Quite right that the Soviets lawfully, according to their own laws, shut that down.
I'm not making any claims about what the Spaniards should or should not have done, only about what they did accomplish: undermining the legitimacy of the referendum.
But by arguing/accepting that you're essentially saying all a state has to do to prevent a secession (however popular) is disrupt the election/referendum process.
It is frequently quite popular to violate people's rights. Holding polls are not the final word in a free society, they are only one leg of the stool.