Is it there by mistake? This is highly unlikely since factories are stocked with plenty of threads and stitching is done automatically.
No, it’s there on purpose, it’s actually a size indicator. Red, blue, yellow… it tells the factory what size that hosiery pair is before it is packaged. This feature helps with quality control too.
This is a red thread on a pair of fleece lined leggings by Gabriella.