Tamerlane, you obviously know your Moroccan history but I have to take issue with you about your concepts about territorial rights. A quick overview of how I see it:
#1- Any change to the statu quo must be peacefully agreed by both sides. Any side who initiates the use of force loses any rights to whine and moan when they take a beating and all other rules are suspended. The UN should just issue a declaration saying “I told you so”.
#2- Geographical contiguity may be apparently a reason to clain a territory if you are a third grader or if you hate learning geography, but in the real world that’s not how it works or Alaska would belong to Canada etc. Geographical contiguity is a factor with very little weight. I am not saying it has no weight but not as much as most people think. The fact that Ceuta is located closer to Morocco than to Spain does not give Morocco any rights except in the demagoguery of Moroccan politicians. Of course, it does have some weight and when you are talking about Macao which was so far away from Portugal that it was really another world, then the weight increases.
#3- The wishes of the local population. Again, this is not a major point. Local populations exist within the context of the greater country and do not have any right to self determination. If all the population of Oregon tomorrow decided they wanted to leave the US and join Canada, it is not like they can do it without consulting the rest of the US. That is because the rest of the US have rights over Oregon which the people of Oregon cannot unilaterally nullify. The fact that the people of Ceuta want to remain Spanish of the people of Gibraltar want to remain British has some weight but not much. It is Spain as a whole who has rights to Ceuta and the UK as a whole who have rights to Gibraltar, not just the locals. And those enclaves could change hands without the individuals losing their citizenship. Of course, if you have a case like Macao or Honkong where the distance is huge and the majority of the population belong to the contiguos country, then things begin to add up.
#4- Practical viability. This means that if the enclave is not practically viable or the present owner cannot defend it, then you are in trouble.
#5- But the main source of any rights are historical rights and this is what carries most weight. Sometimes they are conflicting and/or difficult to evaluate.
So, no two situations are equal and all have many factors which need to be weighed. A quick look at some examples:
Ceuta, Melilla and other Spanish possessions including the Canaries: Very strong historical claim by Spain. Geographically well connected with Spain by sea. The population is mainly Spanish and wants to keep the statu quo. I think Morocco’s claim is very weak and based only in geographical proximity.
Gibraltar: Taken by the UK about 300 years ago. There is a treaty stipulating the conditions (of which I know little). It seems there is a lot for both sides to discuss here because the treaty stipulates the UK cannot alienate it in any way except to return it to Spain. Then the UK have built the airport in part which was supposed to be neutral and I am sure Spain have also messed up in a few places. So, the situation is a bit complicated and there is a lot for both sides to discuss. The locals want to remain British but this cannot be the determining factor, although it has to be taken into account because no one wants a solution which would antagonise the local population. What has to be understood is that the locals do not have a right of sovereignty over Gibraltar. The UK has it and the UK cannot cede it to anyone but to Spain. The British citizens of Gibraltar can retain their citizenship no matter what. At any rate, Spain and the UK are talking about this and no one is going to go to war over it.
Macao: Strong historical claim by possession but weak in every other respect. majority of Chinese population and not very effective Portuguese control or government. The place is just a gambling town. Portugal was happy to get rid of it as it had no use for it. In fact they tried to give it back to China sooner. No problem there.
HongKong: VERY strong historical claim by the UK to Hong Kong but the New Territories were leased and due to be returned and without them HongKong was hardly viable. Add to that the majority of Chinese population, the distance factor and the reality of China growing power and the UK made the right decision in agreeing to return it. It was a practical decision but it does not mean the UK did not have a valid historical claim to HK.
Guantanamo: Any argument that the people there want to remain American is laughable from the point of view of sovereignty rights. US rights are based strictly on whatever lease the US signed with Cuba. The fact that it is strictly a military base means US claim is not strengthened by time as much as if there were a civilian town. I think the US may have some claim to the use but little claim to actual sovereignty.
Channel Islands: Does France even want them?
Israel / Palestine : this has been discussed in many threads taking into account all factors: historical rights, practical viability, wishes of the populations etc.
I cannot think of more examples but I am sure there are many and each has to be evaluated on its own merits. The only rule is that whoever starts a fight cannot whine later if he takes a beating. At least not to me.