You can get it before you leave, if you have a confraternity in your country. Check the links page for confraternities, all that have asked are listed. For example if you live in the UK you can join the Confraternity of St James and get a pilgrims passport from them. You must of course join for them to issue you with a pilgrims passport, please bear this in mind as they get many requests each year from people that are not members hoping to get a pilgrims passport.
A pilgrims passport is a must, you must have one to stay in an Albergue. The passport will have a space for sellos (stamps) on it, this proves that you have walked that day and are entitled to stay in an Albergue (pilgrims only hostel), if there is space, (not normally a problem).
Pilgrim’s passports are also issued in various albergues. In St Jean Pied de Port is where most passports are issued. Pamplona main albergue issue the passports, also the pilgrims office beside the albergue in Roncesvalles. All the main cities, Burgos, Leon, issue the passports, as for the small albergues in between – sorry but I don’t know – if anyone else does let me know and I will post the information here.