What kind of spell are we talking about?
Spell-as-kind vs. spell-as-instance
Sanctuary says
If the warded creature makes an attack, casts a spell that affects an enemy, or deals damage to another creature, this spell ends.
The question here is what does "casts a spell that affects an enemy" mean. It could mean 'casts a spell of the kind of spells that affect enemies', or it could mean 'casts a spell that does result in affecting an enemy'. That is, are we looking at the general kind of the spell-as-category or at the specific effect of the spell-as-instance? It is precisely this distinction that is argued in the related question Sanctuary + readied spell that affects an enemy.
RAW, the text is ambiguous
Unfortunately, the phrase "that affects an enemy" does not appear anywhere else in the PHB. With nothing to compare it to, the best we can say RAW is that it is the DM's call as far as what kind of spell Sanctuary is referring to. If Sanctuary would be ended by the general kind of spells that affect enemies, then since Hold Person is the kind of spell that affects enemies, sanctuary is immediately ended as soon as the Hold Person spell is started. If, on the other hand, Sanctuary would be ended by a specific instance of a spell that does affect an enemy (as Thomas Markov agues in his answer), then sanctuary is not ended because this particular instance of Hold Person did not affect an enemy (since it was Counterspelled before it could have an effect).
If we extrapolate from similar wording, it is likely spell-as-kind
In the aforementioned question, Exempt-Medic's answer points out that although we do not have another example of "that affects an enemy", the phrase is worded similarly to Overchannel1, which says "When you cast a wizard spell...that deals damage". It makes more sense for Overchannel's ability to refer to a general kind of spells, rather than a specific instance of casting. For example, if the evoker wishes to Overchannel scorching ray, it should be sufficient to say 'scorching ray is the kind of spell that deals damage, thus you can Overchannel it'. The alternative, that you can only Overchannel a spell that actually does damage, means telling the wizard 'You have to roll to hit first, because we won't know whether or not you can Overchannel until you actually do damage, since if you miss with all the attacks Overchannel won't work'.
This DM would choose the convenience of spell-as-kind
We need to be careful of making analogies about a different phrasing, but the Overchannel example, to me, suggests the utility in ruling that Sanctuary is referring to the general kind of the spell, not the specific instance. Indeed, thinking about 'what if all the rays miss?', makes it more clear to me that the spirit of Sanctuary is about intent, not result. As a GM, I certainly don't want the headache of players trying to game sanctuary by making arguments like 'they made their save against sacred flame so I didn't affect an enemy, my sanctuary is still up', or 'sure, I cast web, but that doesn't affect the enemy until their next turn, so I didn't affect an enemy when I cast the spell and my sanctuary is still up'. I don't want players trying to cast potentially harmful spells and then retaining their sanctuary if the spell fails.
In the aforementioned question, Groody the Hobgoblin's answer gives the example that a caster could lay down a black tentacles on an area without immediately losing the sanctuary under the spell-as-instance interpretation, but also says that the caster would then lose the sanctuary later, when the tentacles did damage. This brings in the issue of timing; must the enemy be affected 'when you cast'? Does sanctuary end 'If you cast a spell that does affect an enemy at the moment of casting?' or does it end 'If you cast a spell that does affect an enemy, when that enemy is affected'? This is another reason to avoid the interpretation of spell-as-instance; by ruling that sanctuary only cares about the kind of spell you are casting, it is simpler to resolve and you don't have to wait and find out what the spell actually does later. I have to admit I am biased towards rulings that simplify my decisions as a DM rather than those that create even more edge cases.
A JC tweet can be interpreted as spell-as-instance
Jeremy Crawford was once asked about another way to game sanctuary - a cleric casting spirit guardians on themselves, then sanctuary and wading into combat, using the spirit guardians offensively but retaining sanctuary (and see this question).
His response was that, as sanctuary was then written, this exploit was allowed. However, the intent was that "a damaging activity ends the spell". Note that he wrote this tweet in 2016, when sanctuary did not have its 'or the caster deals damage to another creature' clause, since that was added in a 2018 errata. Thus at one level he is just saying what the errata adds - that causing damage to a creature is another end condition for sanctuary. But considering the question he is responding to, we may conclude that he is looking at this as spell-as-instance; he says one may cast spirit guardians without dropping sanctuary because it does not matter that spirit guardians is the kind of spell that affects enemies. The spell only becomes an end condition later, at the point in time that spirit guardians actually does damage. Thus for JC, RAI is spell-as-instance rather than spell-as-kind.
Conclusion
The RAW for sanctuary are ambiguous and thus open to DM interpretation. This DM thinks it is less problematic to assume the 'spell-as-general class' interpretation, but there is certainly support for the opposing view.
1Exempt-Medic also gives helpful examples of other, similarly worded, spells.