Most direct route would be
Madrid to Pamplona by train (about 3.5 hrs from memory)
Then Bus to Roncesvalles (problem here is I think there is only 1 bus per day late afternoon evening and it gets to Roncesvalles in the evening)
Then you have to get to SJPDP by taxi. Helps if there are a few of you.
If there are a few of you you may even want to explore sharing a cab from Pamplona to SJPDP, because it really isnt that far.
A quick search in this forum will give you more details as this has been posted a few times. I just had a quick look but the pages aren't loading. Website must be celebrating the new year
Try again in a little while and you should have no problem.
Or maybe someone else has the details at their finger tips.
Oh just one more thing. I know someone who arrived at Madrid to catch the train to Pamplona and it was full not a single seat left and had to wait a day, so maybe a booking would be useful
Pablo