The story goes like this... at the end of the War of the Spanish Succession, the Treaty of Utrecht was signed which gave the British ownership of Gibraltar, which they had captured in 1704. So in 1713, the British are given control but one of the clauses of the treaty is that if the British ever leave Gibraltar, they must give the Spanish first dibs on getting it back. (The treaty actually used the word "dibs"... well, maybe not.)
Anyway, speed ahead to 1969 and the British give the Gibraltarans? Gibraltarites? Gibraltarers? ummm... the people of Gibraltar a constitution which guarantees that they will never be given over to another country unless the people of Gibraltar give their approval. So where does this leave us... the British can only give up Gibraltar to Spain (Treaty of Utrecht - 1713) and they can only give it to Spain if the people of Gibraltar support it (Gibraltar Constitution - 1969).
But the people of Gibraltar don't want to be ruled by Spain or Britian. They want independence. But the British can't give independence without Spain's approval. And Spain wants Gibraltar back. So the British are stuck. They can never leave Gibraltar without the approval of both the people of Gibraltar and Spain, an approval that they are unlikely to get anytime soon. All because of of a treaty that is almost 300 years old.