This thread’s train of thought was wildly interesting to me, because like a lot of y’all, I assumed it was so they didn’t drown. Turns out it’s mostly not that probably, but kind of a little of that? Here is the Scientific American article and one from PennState Extension I found useful.
Bizarrely, this is a pretty contested question. It appears that the outdated assumption was because they would drown, but more recent consensus say that isn’t largely true, because they can survive for ~2 weeks submerged in water, and we know they do require it to be able to like, exist and not fry to death on the sidewalk. However, even more weirdly, apparently under very specific conditions they can “drown.”
It’s not really drowning, it’s suffocation, because sometimes waterlogged soils don’t have enough oxygen inside of the water that floods all of the subspaces with air pockets inside of the soil for them to be able to live. So they do die from the water, but not because of the water replacing air necessarily, it’s because the water itself isn’t oxygenated enough for them to tolerate it replacing air. But if it were they’d be getting along just swimmingly. (They breathe oxygen through their skin, and have to be wet for it to dissolve properly. That’s why they have gooey mucus.)
I’ll go out on a limb and say it’s likely that if the water is warmed, (as is common from urban runoff, due to accruing heat from dark, impermeable, hot surfaces like asphalt or sidewalks, allowing for maximal contact time between the surface and water) then this might play a role, as warmer water dissolves less oxygen (as fellow tropical aquaria enthusiasts know!) Any pollutants ferried in the water that the squirmy wormies are slurping up through their skin might also be a factor, but it’d depend, and I’d imagine urban earthworms are fairly tolerant of all the nasties in our ecosystem.
Apparently there are a couple of ideas as to why they do this- the drumming of rain on soil sounds similar to moles, which predate them, but a few species display mating behaviour in response to rainfall so they squirm their way up to the top to meet up with other worms, and more generally it could just be that they’re taking advantage of their increased range of travel (before they would dry out) to migrate somewhere new.
Also if you’ve read this far in the worm-y tirade, I’m going to remind you that the USA and Canada are experiencing invasive hammerhead worms that are decimating local populations of earthworms, slugs, and snails. They’re apparently doing amazing with climate change, which sucks for us. Like the Spotted Lanternfly, the current recommendation is to kill them on sight. They recommend not cutting or squishing, and to instead pop them into a jar of rubbing alcohol.