That's the crux of the matter in today's world and the Spanish are hypocritical when demanding Gibraltar back.The Russians had an easy time with Crimeea because, illegal as their occupation is, most of the population is pro Russian. The same with Northern Cyprus but that's not the case with Gibraltar, Ceuta, Melila, Falklands where local population wants the current status quo maintained.The problem is the people of the Falklands want the British. Ceuta and Melila want Spain. Gibraltar has the same problem the people want to be with Britain rather than Spain.
Its going to be hard to convince the people to join another country.
Ceuta and Melilla are not even Muslim majorities they are catholic. Muslims either had to convert, leave or get killed.
Spanish had these enclaves in Algeria until Ottoman Algeria kicked most of them out. Last one Oran was sold to the Dey because the Spanish can no longer hold the city due to multiple attacks and raids.
A huge country like Indonesia couldn't hold on to a small patch of land like East Timor because the locals were totally against it.