Heraldry, or at least colors (for the lower ranks). If the leader has a gold lion on a red background, that army would wear red (tabard, armband). The other leader let’s say has a shield that’s divided blue & silver, so that one wears blue.
In a modern medieval reenactment group, supporters of one side have swatches of red tape put on their helms (front, sides, back), the other team gets blue. Doesn’t matter so much the rest of what’s worn… look at the head before you hit.
And as others have said, spies happen. If the spy has the appearance (body as well as clothing) and the linguistic skills to infiltrate, s/he also needs some way to tell the home team “friend – don’t shoot!” when returning. Password of the day, for example. Literally a word that lets you pass a checkpoint.
Latest Answers