It seems fairly clear (or at least plausible) what Spain was hoping to gain by NATO membership, which was consummated as a rather later affair in the closing decade of the Cold War:
The main reasons why the Government of Spain sought membership of the Atlantic Alliance were geopolitical, however. Given its military vulnerability, Spain, a country on the Iberian Peninsula, wanted to join NATO so as to guarantee its territorial integrity and thereby reinforce the security of the Balearic– Gibraltar Strait–Canary Islands axis by protecting it from possible foreign expansionism, principally from Morocco, which, having annexed Ifni and Western Sahara, now had ambitions to conquer the two Spanish cities in North Africa: Ceuta and Melilla. The Spanish Government furthermore feared potential offensive posturing by two other North African countries, Algeria and Libya, which were in the Soviet orbit. The Government also stated that Spain’s entry into NATO would merely ratify de jure a situation that already existed de facto under its agreements with the United States, namely the fact that Spain belonged to the Western defence system. Spain was also convinced that joining NATO would break the deadlock in negotiations for entry into the European Economic Community.
The [Socialist] Spanish government even put out a pamphlet that they were not giving up on the the goal of recovering Gibraltar by joining NATO. Despite these apparently convincing points, the Spanish population wasn't incredibly sold on the matter, with the NATO membership referendum in Spain passing with (just) 52.5% in favor.
It's not unheard of for countries to oppose NATO membership of those with whom they have some territorial dispute[s] with. So, I'm curious why did the UK agree to Spain's NATO membership seemingly without any concession from Spain on the matter of Gibraltar. Were there e.g. any discussions in UK's Parliament on the matter of getting some concessions from Spain regarding Gibraltar in relation to Spain's NATO accession? Were there overriding considerations?