Whilst unlikely to occur on any of the main camino routes, anything is of course a possibility. Normally I would simply ask at the nearest bar for suggestions, worst case get a taxi elsewhere.
That said you ask how would I deal with it. Whilst I've never done it on Camino, in my traveling years I frequently 'emergency camped '. My sole equipment was my sleeping bag and an emergency blanket. The latter I used as a groundsheet. Nowadays I'd probably add my mosquito net to the mix (head net, tiny, weighs 37 grams and is always with me anyway). Ditto my poncho - dark blue, nice and stealthy!
I never slept in a church doorway, rather in some sheltered slightly out of the way area. (Of course if you found one with a nice shady portico on the edge of town it might be ideal)
I've slept under Bridges, in an abandoned goat shed (I swept it out with dried grass first!) plenty of abandoned buildings - mainly old sheds in various stages of repair - under boats, and, more likely in Spain, picnic tables.
I occasionally got bitten by mosquitoes etc, and once a bunch of youth arrived to sit down and share some beers at the picnic table I was sheltering under at 2am (I startled the hell out of them when I arose from the depths), but other than that I've had no issues.
My general rule of thumb is to look for somewhere that is relatively quiet and there's not too much litter. Litter = people. As of course do well-beaten paths.
Going just a few meters into the bushes from a well-beaten path into the shadows, preferably up against a wall (and if there's any possibility of precipitation with some kind of roof) will see you sorted. Anything you can find to help make you more comfortable is a bonus - (dry) cardboard for example is brilliant. However, if you can get out of town you're better off, as
@Bradypus point's out.
If you really want to prep for it, consider a bivvy bag and mat as
@Bradypus says.
But frankly, unless it's something you really want to try - I'd just plan to call a taxi.
If, on the other hand, you plan to do one of the routes in France, then I would take a lightweight tent, a warmer sleeping bag and a proper sleeping mat rather than just a short variant. It's exactly what I have just packed - Lanshan 1 Pro, sleeping mat and sleeping bag together come in under 2 kgs. But opportunities for camping in Spain and Portugal are significantly more limited (although some happily do it, and I may very well too when I get there). But that's a whole different story.