Lots (but not all) of the municipal albergues will sell you a credencial. If you check the albergues on Gronze, under "servicios" they'll tell you whether or not they "expiden la credencial". Unfortunately the albergue in Castro Urdiales does not seem to provide this service. FYI, it's also a tiny albergue (only 16 beds), so in August you're unlikely to get a bed unless you're there very early.
In Bilbao you'd need to get your credencial at the municipal albergue, which is about 2km from the bus station. According to Gronze, the next stops for the credencial are Portugalete and Pobena.
Edit: just checked on Google maps, and they're saying there's a 1.2km route to the albergue from Bilbao bus station. The albergue is on the outskirts of the city, however, and you'd have to cross some very busy roads and highways, so I'm not sure of the feasibility of this, but I'll attach a screenshot just in case. The albergue only opens at 15h00.