Be it pre-1900 or after, the UK decides - to improve relations with Spain (or bribe it to do something) to swap Gibraltar for Ceuta.
Or maybe, post WWI (WWII?), Britain deems Gibraltar simply too small - not enough space for naval facilities, stores, staging ground for troops, airfields...