SJPdP is connected to Gare Bayonne by SNCF train and Transports64 buses.
SJPdP is connected to Pamplona by CONDA (ALSA) bus.
The closest airport to SJPdP is Biarritz Airport BIQ.
So your objective is to get from Madrid to either of Bayonne or Pamplona and onward to SJPdP.
a. Madrid is connected to Pamplona by Renfe train, bus or flights to PNA airport. Catch CONDA bus from Pamplona to SJPdP. This is the least complicated but the bus schedule from Pamplona to SJPdP is limited.
The bus is popular because some ALSA (and PLM Autocares) buses pick up at Madrid Airport. Its also popular because there is no transfer from Pamplona train station to bus station. There are more buses leaving from Madrid Avenida de America that don't make a stop at the airport. Note ALSA buses involve a transfer at either Soria or Zaragosa.
The train is popular because it is fast and comfortable.
Flights are expensive.
b. Madrid is connected to Irun by Renfe train. Use Donostialdea Metro to get from Irun Renfe station to Gare d'Hendaye. Take an SNCF train or Transports64 bus from Gare d'Hendaye to Bayonne.
This is the most complicated route because of the transfer from Irun Renfe station across the border to Gare d'Hendaye. Note some Renfe trains terminate in Hendaye. Its a distance of 3 km from Renfe station to SNCF station.
c. Madrid MAD is connected to Biarritz BIQ by airlines (Air Iberia). Biarritz/Anglet/Bayonne airport is connected to Gare Bayonne by Chronoplus bus #14. This is probably the most expensive route.
Alternatively fly to San Sebastian EAS airport, located 5 km from Gare d'Hendaye ... handy to the SNCF train network. described at b.
d. It is possible to take an ALSA bus from Madrid to San Sebastian. ALSA and PESA provide bus service from San Sebastian to Bayonne and from San Sebastian to SJPdP via Pamplona.
e. There are other permutations.
Getting around in Madrid:
Madrid Airport is served by Cercanias train, Madrid Metro (Subway), and EMT Madrid bus.
Avenida de America is accessed by EMT Madrid bus #200 and by Metro from either T1T2T3 or T4.
Most trains to Pamplona leave from Renfe Puerta de Atocha. Access Atocha by Cercanias from T4, Metro or EMT Aeropuerto Express #203 bus from T1T2T3 or T4 .
The other station is Renfe Chamartin. Chamartin is accessed by Cercanias from T4 or Metro from T1T2T3 or T4.