Hello and thank you for your inquiry,
Without seeing the worms it is hard to tell what they are. My best guess is they are simply a scavenger that has been feeding off the detritus at the bottom of the pond. I don't think they were the cause of the death of your fish. More than likely the two new ones brought in some type of disease the caused the issue.
As far as how did they get there? There are a few different ways, but more than likely they were brought in with some type of livestock (fish, birds, frog, etc...) that may have injested their eggs.
If possible you may want to quarantine any new fish coming in before putting them in your pond to help prevent any disease from being introduced to the pond.
If there is anything else we can do for you please let us know.