Also, if Spain is like most countries (but I really don't know this for a fact), but elected representatives will have signed or sworn or something similar to uphold the constitution.
I think the legitimacy difference has to do with inalienable rights. People have a right to representation in their own governance. That's what the dictator gets wrong. People also have a right to liberty - i.e. To not be slaves. A "law" that says you can't ever secede is making people slaves by taking away their right to withdraw from the political union they're a part of.
The argument above is that it's legal because it's written down. What I hoped to call attention to is that simply writing something down and calling it a law isn't necessarily better than what a dictator does.