ON one of my visits to Barcelona, I was given a tour of the Catalan parliament building, in the tranquil Parc de Ciutadella. Its history is anything but tranquil. The parliament building was seized by the fascist dictator, Francisco Franco, in 1939 for use as a military barracks after the Spanish Civil War. The President of Catalonia, Lluis Companys, was tortured and then shot nearby in 1940. I was shown bullet holes on the city walls, left unrestored to remind visitors that democracy doesn't come cheap.

Politics is a serious business in Catalonia. It isn't hard to understand why tens of thousands took to the streets of Barcelona last week to protest against the Spanish government's heavy-handed attempt to halt next month's unauthorised referendum on Catalan independence. Imagine 700 mayors being taken to court for organising a vote. (Yes, I know – imagine if we had 700 mayors in Scotland). The Spanish government in Madrid has sent in the Civil Guard to occupy government buildings in Barcelona and arrest government ministers and officials. Campaign material and ballot papers have been seized, demonstrations banned, newspaper editors arrested. Madrid has even threatened to cut off power supplies to the city and has tried to seize control of the Catalan government's finances.

Viewed from the soberly democratic UK, this seems almost unbelievable. Do governments actually behave like this in the 21st century? The Yes Scotland campaign may have accused the UK Government of being heavy-handed with its propaganda during the 2014 Scottish referendum, but Westminster never engaged in active repression. And for a very good reason: by resorting to this kind of authoritarian behaviour the Spanish government has, I believe, almost guaranteed the disintegration of the Spanish state. These images will endure. Trust has evaporated. Barcelona looks and feels to many in the city as if it is under military occupation again, just as it was 80 years ago. The Spanish prime minister, Mariano Rajoy, has ignited a grievance in the region that can only fuel demands for independence. Surely, the Catalans say, the spirit of Franco lives on in Madrid.

Of course, right is not all on one side. The Spanish constitution is unlike the UK's, and there is no right of secession under Spanish law. The referendum on October 1 has been declared illegal by the Spanish Constitutional Court, and many will boycott it for that reason. Other Spanish regions suspect that wealthy Catalonia is simply trying to wriggle out of its fiscal responsibilities to less prosperous provinces, just as the country is recovering from the sovereign debt crisis. Catalonia, with its population of only 7 million, accounts for 20 per cent of Spain's GDP and a disproportionate amount of its tax revenue. This is rather the reverse of the situation in the UK, where Scotland has always been regarded as the “subsidy junkie”. Many see the Catalan leader, Carles Puigdemont, as a nationalist opportunist – more Nigel Farage than Nicola Sturgeon.

On the other hand, Catalonia, unlike Scotland, has its own language and distinct culture, which dates back 1000 years and has endured repression for almost as long. Catalan nationhood and identity has never been recognised in the way Scotland’s has been, more or less, since the Union of 1707. The parliament, the Generalitat, which voted for the referendum, is regarded as the legitimate expression of the will of the people in Catalonia. The right of self-determination is one of the founding principles of the United Nations, and the European Union. It's hard to argue with that kind of mandate.

Puigdemont has called on the European Union to intervene on the grounds that the Spanish central government has violated the European Charter of Fundamental Rights. However, Brussels is even more desperate to avoid involvement in internal Spanish politics than it was in the UK's before the 2014 referendum. The Charter anyway only applies to the implementation of EU law in the member state. Brussels insists that fundamental freedoms are guaranteed by the nation's own constitution, and any international conventions to which it has signed up – like the European Convention on Human Rights. The Catalans might have more success going directly to the European Court of Human Rights in Strasbourg with their complaint.

For its part, the Spanish government insists that there is formally no right of unilateral secession under in international law. This is technically correct. Separatism is held to breach the territorial integrity of the state, which has been the foundation of international law since the the 17th century. However, since the anti-colonial era, after the Second World War, a new concept of lawful secession as been established in international law that underpins the United Nations Charter, to which Spain is a signatory. This Charter states that “all peoples”, not just all nation states, have the inalienable right to self-determination.

Thus, when a people believe this right is being denied, as in Kosovo in 1999, and when there is a clear and unequivocal expression of that desire in a legal referendum, then secession is deemed lawful. The ultimate test of whether a claim for independence is legitimate, it follows, is a referendum, and that is what is being denied to the people of Catalonia. The ground rules were laid down by the Canadian Constitutional Court in the Clarity Act in 2000, following two referendums on Quebec independence. These principles lay behind the Edinburgh Agreement in 2012, between Alex Salmond and David Cameron, which authorised the legally binding Scottish independence referendum of 2014.

However, this isn't really a question of formal legality, but of practical politics. Madrid is not only on weak ground in international law, it is also failing to act reasonably and in its own long-term interests. These days, governments simply can't win by denying people the right to vote and democratic freedom of expression. In doing so, Mariano Rajoy can only boost support for separation, which until now has been a minority cause in Catalonia.

Madrid should have learned the lesson of the Scottish referendum in 2014. That result was close, with 45 per cent of the Scottish voters, 1.5 million people, voting Yes to independence. Yet in Scotland there was no civil disturbance after the No vote. The Yessers were disappointed, certainly, and some were convinced that Scotland had been robbed. But everyone accepted the result, and agreed that the issue had been resolved, as Alex Salmond said, for a generation. That would have been that, had it not been for another referendum, the 2016 Brexit referendum, which unexpectedly reopened the issue ... but that's another story.

The point is that in Scotland, everyone accepted what Nicola Sturgeon called “the shining example” of the Edinburgh Agreement, and she was right at First Minister's Questions last week, to call on Mariano Rajoy to follow that example in Spain. Those images of armed police taking over government offices have appalled international opinion. Catalan nationalism, unlike its Basque equivalent, has always been peaceful, but this is not the way to keep it so. Rajoy will have to grant a referendum eventually, and by acting like a dictator he will simply have persuaded many undecided Catalans that they need the protection of their own state. The UN may soon have to find space for another national flag outside its New York headquarters.