When checking to find out what kind of earthworm we might be discussing, I found sources listing anywhere from 100 to over 6,000 species. That wasn't very helpful so I'll just skip it and assume you have some common variety of earthworm that's present around many parts of the world!
The short answer here is that they were most likely trying to get to a place where they could dig a tunnel, and succumbed to the elements along the way. The actual elements, however, may not be exactly what we had in mind. It doesn't sound like it got cold enough to freeze them, so I doubt that's why they died. (An interesting fact from here is that earthworms can freeze solid and still live if the freeze is slow and they do not thaw out and refreeze often. I don't think that applies here, though!) Likely it was a combination of things, including a few that DudeOnRock already mentioned.
Earthworms always have tunnels, but as the weather gets cooler, they dig deeper and wider in preparation for the winter. A quick temperature drop can cause them to come out for a short while instead. They don't come looking for warmth, though, but as a mission to find a different place in your yard to dig more trails and hunker down for the winter. They may also grab some snacks, like bugs, along the way, to give them energy for the cold weather to come. Your stones are pretty tight, but there may have been something in the crevices that they wanted to eat.
The most common cause of environmental earthworm death is dryness, and I think that's the bottom line here. Something happened along the way which caused them to dry out, which resulted in their demise.
Earthworms breathe, meaning get oxygen, through their skin. Without enough oxygen, they literally suffocate. In order to absorb the oxygen, however, they must be wet all of the time. This explains the coating of slime (mucus). It's protective.
Q. How do earthworms breathe?
A. Earthworms respire through their skin, and therefore require humid conditions to prevent drying out. They coat themselves in mucus to enable the passage of dissolved oxygen into their bloodstream. Source.
They need to be wet to dig the tunnels for the winter, (up to about 6 feet or 2 meters, depending on the location and species), to eat, and to procreate. They have no bones, and move through a series of muscle movements which only function when wet.
If it had recently rained, and your stones were wet, they may have been attempting to use them as a shortcut to their final destination. One of the reasons earthworms come up in the rain is to make traveling easier.
Q. Why do worms come onto driveways and sidewalks when it rains?
A. Dr. Dennis Linden, Cindy Hale, and other worm experts say that worms come to the surface during rains (especially in the spring) so they can move overland. The temporarily wet conditions give worms a chance to move safely to new places. After rain or during high humidity are safe times for worms to move around without dehydrating. Source
From Why are earthworms taking over my driveway
When the soil is too dry, they burrow deeper to find moisture. When the soil is wet, they move closer to the surface. When there is adequate surface moisture or humidity, they venture out above ground and look for new places to burrow.
Even if your terrace was nice and warm, they would not have been looking for a warm place to hang out. In general, it's very dangerous for earthworms to be out during the day. Light dries them out, literally paralyzing them when they're in it for more than an hour. They lose the ability to seek a safe spot, and die on the rocks.
Also, basements and garages can not support life for earthworms, so they're not generally programmed to seek shelter in those areas. They may be protected from harsh temperatures, but since there's no opportunity for digging, eating, obtaining moisture, or hibernating they'll pretty much always die. If you ever find a live earthworm inside, putting it out may save it. Even if it's winter, if you can dig an area in the dirt more than a few inches deep, putting them in it can give them a fighting chance. Most likely they'll freeze, but not always.
This brings us back to where we started. I believe they were on their way to a place for a permanent winter home, and something happened along the way which caused them to dry out. That dryness was the likely cause of death.
This wasn't true in your case, but it's worth knowing that earthworms which are curled into a round ball are usually alive, even if you don't see them moving. Due to a variety of environmental factors, they enter a state similar to hibernation, in that their metabolism slows down, but the worms are awake. In winter, it's called "diapause", and in the summer it's called aestivation. Curling up is mostly to preserve their water and oxygen. If you find them like that, they should be carried to a warm, moist area on the grass, if you have one. At some point, they'll come out of it and go about their activities.