I'm taking the 10:45 ALSA bus from T4 to Pamplona bus station, staying overnight in Pamplona rather near the bus station to rest after the long flight and have a look at Pamplona so I can blow through on the way back if I want to. The next a.m., taking the 10 a.m. Conda/ALSA bus from Pamplona to SJPP and staying another night there because I've heard it's a nice little town and I have items to pick up (a trekking pole and Compeed). I had some trouble booking the buses online through both ALSA and Movelia - a convoluted process involving figuring out where the system's glitches are for foreign users - it helped to turn off the automatic translation under settings beforehand.
There is train, bus, and airplane service from Madrid to Pamplona. The most comfortable is the train. The ALSA bus has the most frequent service and some buses pick up at the Madrid airport T4. There is seasonal limited CONDA bus service from Pamplona to SJPdP.
The other way is to go to Irun or Hendaye by Renfe train. Then cross the border (if the train doesn't terminate in Hendaye) and take an SNCF train from Hendaye to Bayonne. There is another SNCF train/bus service from Bayonne to SJPdP - typically 4 times per day all year. There are a lot of variables on this route including bus from Madrid to San Sebastian, Euskotren from San Sebastian to Hendaye, Transports64 bus to Bayonne, and the San Sebastian Airport is located 3km from Irun Renfe station.
If you haven't bought your plane ticket yet, I would look into adding on Madrid-Pamplona and Santiago-Madrid. This is called an open jaw or multi-city ticket. I started doing this about 5 years ago because of a suggestion I got on the forum and I find it rarely adds that much to the round trip international ticket price and it saves a lot of time and expense. And it means you don't have to spend an extra night in Pamplona or Santiago.
Once in Pamplona, you can easily get to SJPP as others have described. Buen camino, Laurie