Where I was going with that is that if you were using coffee filters to cover the drainage holes it isn't likely that the worms got in that way because there are no openings. With insect screening it would depend how small they were at the time whether they could get in through the mesh. If they're in pots that are similarly blocked, then it points to their already being in the mix in which case covering the holes would also stop them from getting out.
A possible way to get them out of the top of the pots would be with lemon-scented liquid hand "dish soap" at about one or two tablespoons per gallon of water poured through the pot. But I'd only try this on one or two pots in case it damages the plants. I suggest this because one of my tasks where I work is monitoring turf for pests and diseases. To check for pests I pour diluted lemon "dish soap" onto an area of turf and then wait for the insects to climb out to get away from it and then identify and count them. In the process of this, any earthworms present also come out onto the surface seemingly very uncomfortable from the "soap" solution. To avoid the soap damaging the turf, especially if it is sunny, I flush afterwards with plain water (including the earthworms hoping they'll feel better!) hence I would also flush through the pots with copious amounts of plain water afterwards. Might be worth a try but a little risky.