Because the people who live there overwhelmingly (98%–99%) vote in favour of remaining British.
https://en.wikipedia.org/wiki/1967_Gibraltar_sovereignty_ref...
https://en.wikipedia.org/wiki/2002_Gibraltar_sovereignty_ref...