The whole point of having a constitution is to prevent governments from going full retard.
OTOH, when a people/country want to go full retard a constitution isn't going to stop them. They will change it or ignore it or pretend it means whatever they want. Any constitution (including religious texts) can be creatively interpreted to mean whatever the user wants.
A constitution is no better than the people who implement it and use it. Decades ago I used to give an example to people who thought a well written constitution is the answer to everything. I would ask them, what do you think is better? A country with a written constitution that guarantees civil rights, jobs, housing, no state religion, etc. Or a country with no written constitution, with no such guarantees, with the state endorsing a certain religion, etc.
When they would answer that the first is obviously better I would ask "so you would rather live in the Soviet Union than in the UK?"
The UK has a strange system of government which logically makes no sense and yet it has given excellent results over the centuries because the people and their representatives were bound by tradition and they used good judgment and tolerance. That culture is much more important than any written constitution.
I want my country to participate in international treaties. I believe it is good that we give up some sovereignty in exchange for having a say in other countries affairs. That makes international relations and commerce easier and better and makes wars less likely. That is a sign of civilization. Countries that want to not have limits or bounds are dangerous to world stability. A civilized individual submits to the laws that his society has chosen to impose and a civilized country submits to the laws that have been agreed by all nations.
The UK referendum wasn't legally binding, as I believe those in Switzerland are, so the government wouldn't have to go to court, but in order to stop Brexit, they need to do so in a manner which appears to be legitimate, otherwise there's a risk of serious civil disorder and even more distrust in government. Another referendum because court deciding the result was invalid would be a good way to keep the peace.
Part of the mess is that the referendum is considered binding and not binding at the same time. Legally it is not binding as Parliament is supreme and sovereign. OTOH politically the "winners" want to make it look like it is binding in spite of the confusion and irregularities.
Everybody involved have messed up big time and it is a shameful spectacle the UK is giving.