What is a good way to get from Gibraltar to Pamplona? Then Pamplona to Lisbon.
From Gibraltar to Jerez or Malaga for flights to Pamplona (via Madrid).
Fly Pamplona to Lisbon (again via Madrid).
From Gibraltar by bus to Algeciras, then train to Madrid, and train to Pamplona.
Pamplona to Madrid by train, then night train to Madrid.
What do you want from 'good'?
By good I meant not too complicated, expensive and not in a plane unless the alternatives take more than a day or two.
Pete, you can do a "reasonableness test" with Google Maps. That gives a trip of over 10 hours by surface transit, which does not account for getting stuck behind tractor-trailers going up hills, or waiting to change busses. I personally found the trip from Ronda to Gibraltar to be annoyingly long (but on excellent roads.) I would also suggest that Gibraltar and Pamplona are not the two best attractions for visitors to Spain, but that's your decision. I would never go from Gibraltar to Pamplona, San Fermin time or not.
You really need to say whether you are traveling with zero dollars and a backpack, or via hotels with infinity pools.
You also have the option of a shorter bus ride from Gibraltar to Algeciras, then train from there takes 10 hours with 1-2 connections. Trains departing Seville are faster (6 hours, 1 connection), but the bus ride to get there from Gibraltar is 4 hours.
If taking the train from Pamplona to Lisbon, you might not need to go all the way to Madrid to catch the night train; you can currently connect to one at Vitoria/Gasteiz, but that schedule is only published through Sept. 12 (running Mon-Sat).
How to Look Up Train Schedules and Routes Online gives you the DB train schedule link and tips for using it.