RAW, an unaffected creature must be seen when the spell is cast.
The RAW ruling here is pretty clear. The relevant portion of spirit guardians‘ spell description says:
When you cast this spell, you can designate any number of creatures you can see to be unaffected by it.
You must be able to see the creature when you cast the spell to be able to designate it as an unaffected creature.
Rules-as-fun may call for a different ruling – discuss it with your table.
I’ve played in games that ruled this both ways. At one table, we were all very committed to rules-as-written, and were aware of this feature of the spell. We had no problems with ruling the RAW way here, as we were all aware of its tactical implications before it was ever used.
At a different table, most of the players were less experienced, and our cleric was rather disappointed when the DM suggested the RAW ruling. We took a minute to talk about it, and decided that we go with “no friendly fire”, and that worked just fine for that table.
If you’re a DM and one of your players has spirit guardians, talk it through with them before you have to rule on it in play – it can be an unpleasant surprise if you haven’t thought through the details of the description and how it plays out tactically.