The saint, the midsummer and the blood
The common name comes from timing. The plant flowers around the shortest nights of the year, close enough to the feast of St John the Baptist on the twenty fourth of June for the association to stick across most of Europe. Wort is simply the old word for a useful plant.
The red juice did the rest. Squeezing the buds on that particular date and getting what looks like blood was read as a sign, and the plant was understood to be marked with the blood of a beheaded saint. It was hung over doorways and windows at midsummer, burned in bonfires and carried against storms, illness and the evil eye, and it acquired the Latin nickname fuga daemonum, the flight of demons.
Folklore usually attaches to plants that do something, and this one does. The pigment that made it holy is a genuinely active compound, which is a rare case of the superstition and the pharmacology pointing at the same molecule.