I'm not sure if it's compulsory for visitors to carry their passports but I always advise my customers to leave it at the hostel.
There are a few situations when they must show it:
* At banks you are required to show it when changing money.
* If you are a EU citizen and want to take advantage of free entrance to
Patrimonio Nacional places on Wednesdays you must show your passport to prove your nationality.
* Shopkeepers in Spain should ask for it to verify your sign when paying with credit card.
You may want to try a color photocopy of the passport. In some EU countries people may have have both passport and national ID card. The latter is acceptable in Spain as ID so you won't have any problems leaving it at the hostel.
The reason why we always advice not to take it with you it's because loosing your passport is a big problem and it may take a while to get a new one through your embassy.