In Madrid Credenciales and a sello are available from the offices of the Archdiocese beside the Cathedral and I think Javier recently posted also from the Amigos who meet a couple of times a week in the Church of Santiago which isn't far from the Cathedral.
Otherwise credenciales are usually available in albergues - you will need one if you intend to use albergues on the journey but as has been said you only require sellos for the last 100 kms. But lots of us fine the collection of stamps along the way is a great reminder of a fantastic journey.
I misplaced the one I got at the cathedral in Sevilla and got another one in the albergue in Merida. In between I had a sheet of paper stamped in each town until I arrived in Merida in case the albergues had an issue with me not having a stamped credencial. The one from Merida is a very nice one although the sellos fit a little awkwardly. But you can get one there in the albergue.
Peaceable Projects Inc. is a U.S.-based non-profit group that brings the vast resources of the wide world together with the ongoing needs of the people who live, work, and travel on the Camino de Santiago pilgrim trail network in Spain.