Granted, I haven't traveled with a bike before, but if it's in a box, why not take the bus? It could be stored in the luggage compartment.
As for getting to SJP from Madrid, that should be no problem. You *may* have to go out of your way a bit, since the only way to get from Roncesvalles to...