You may take a bus out of the airport itself (Terminal 4). PLM (
http://plmautocares.com) has a bus from Madrid's airport to Pamplona six days per week. If the schedule of that bus doesn't suit you, Alsa (
www.alsa.es/en) has more options but they mean a change of buses along the route (most likely in Soria) although that shouldn't be worse than communting from Madrid's airport to the downtown to take a bus or a train. Alsa has an office at the airport where you can get tickets for the next bus with available seats (if you didn't book your tickets in advance). If Alsa's schedule out of the airport didn't suit you either, you would need to go to downtown Madrid (Intercambiador de Avenida de América) from where there are more buses to Pamplona than out of the airport. In that case, to travel with PLM that makes the route direct (i.e.: without any change of buses along the route) would be IMHO better than with Alsa (because Alsa means a change of buses along the route). The bus station in Pamplona is on the city center.
By train, you would need to take the express bus (
www.emtmadrid.com/Aeropuerto) to go from the airport to Atocha. There are commuter trains too linking the airport with Atocha but there are works on the tracks and you have to make part of the route by bus so till the works on the tracks are finished, the express bus is the best option. Trains from Madrid Puerta de Atocha to Pamplona are direct (take a look at the web of RENFE -www.renfe.com- for info about schedules, fares...). The train station in Pamplona is a bit far away from the city center.
Bus has the advantage that you (can) avoid getting to downtown Madrid and it leaves you at a more centric place in Pamplona than the train. Otherwise, train or bus is a matter of personal preferences. Regarding missing connections due to a delayed flight, read the terms and conditions of the fare you book to know what are that fare's rules about that question. If you don't bother to pay full fare, you could book your ticket once on the ground. That means a little bit of flexibility in case some bus or train was full but there are enough options as to find someone with available seats.