Alsa bus does the journey from Pamplona to Saint Jean Pied de Port daily (during the summer) at 10:00, 12:00, 14:30, and 17:30. You should book a ticket in advance, as August will be really busy.
Your best option from Madrid to Pamplona is the bus that leaves from outside the airport Terminal 4 at 10:45am (also Alsa). This will get you to Pamplona bus station at 15:35, in time for the 17:30 bus to SJPP.
With this option you avoid going into Madrid. However, if you wanted to spend a couple of hours in Madrid (you are arriving very early, after all!) you could catch the 11:35 train (from Madrid centre). The train's much quicker (you'd arrive in Pamplona 14:40), but this option might be more stressful as you'd need to navigate across the city and between bus/train stations, etc.