My best guess here is that somehow or another, a viable earthworm egg got into the tank and survived. Possible vectors for the egg could have been rocks collected from outside, your gravel, plants, or even your fish food I suppose.