I was alway taught that it did refer to an outsider coming first - but more specifically to the practice of applying dye to the lighter hair on a horse in order to disguise its distinguishing features -which would have immediately identified it as a potential winner.
As the dye wore off during or after the race, the true identity of a winner was revealed.