Both castings of sanctuary end1
Sanctuary is clear in that:
If the warded creature makes an attack, casts a spell that affects an enemy, or deals damage to another creature, this spell ends.
In this answer, we are concerned about the "casts a spell that affects an enemy" clause.
Casual users of English (myself included, in everyday conversation) use "that" and "which" to introduce clauses largely interchangeably. But there is a difference in their formal grammatical meaning, and this difference is maintained in several other game features.
'That' opens a restrictive clause
'That' is used to introduce a clause setting apart its specific members as being distinct from a larger group.
When the recipient of a sanctuary spell
casts a spell that affects an enemy
this means they are casting a spell 'of the type of spells capable by design of affecting others'. Whether or not the spell subsequently results in an enemy actually being affected is immaterial; "that" is simply identifying the category of spell to which inflict wounds belongs. And in fact, inflict wounds is the kind of spell that can (on a hit) result in damage; it can affect enemies, and thus sanctuary would drop the moment it was cast, before any enemies were actually damaged.
'Which' opens a nonrestrictive clause
'Which' is used to introduce a clause describing what is incidentally particular to a specific member of a group, without defining it as categorically distinct from a larger group.
Further, these non-restrictive clauses are often set off by commas. Thus, if the intent was to have sanctuary ended only by spells 'that actually happened to result in an enemy being affected', the correct use of language would have been to say:
If the warded creature makes an attack, casts a spell, which affects an enemy, or deals damage to another creature, this spell ends.
Here, whether or not the spell actually results in an enemy being affected is crucial; "which" does not identify the kind of spell to which inflict wounds belongs, but rather indicates that sanctuary would drop if and only if an enemy was affected by the damage.
By selecting "that" rather than "which", the writers of the sanctuary spell indicated that the spell reacts to the kind of spell being cast, not what its subsequent effects are.
This "that vs. which" distinction is key to understanding how to interpret other game features as well, including the Storm Sorcerer's Heart of the Storm feature, the School of Evocation Wizard's Overchannel and Sculpt Spell, and the sorcerer's Careful Spell metamagic. In all four of these examples, "that" opens a restrictive clause. Reading "that" as meaning "which" completely changes how these abilities work, and in the case of Heart of the Storm, would result in a feature that never worked. Sanctuary is a little different in that it could work as a nonrestrictive clause, just in a different way, and this is certainly a source of confusion when people attempt to interpret it like that. However, given the abundant examples of "that means that" in other features, it is safe to conclude that the authors of sanctuary actually meant to use "that" in its correct grammatical sense.
Casting inflict wounds will immediately drop sanctuary on the caster, even before the attack roll is made.
The familiar is treated "as if" it had cast
Find familiar says:
when you cast a spell with a range of touch, your familiar can deliver the spell as if it had cast the spell.
Here, "as if" means that the familiar does not actually cast the spell, but is treated as if it had. We know, by the way, that the familiar did not actually cast the spell, because the inflict wounds spell begins with:
Make a melee spell attack against a creature you can reach
while the description of find familiar says:
A familiar can't attack
Thus, we know that the caster is casting the spell (and their sanctuary drops immediately), and the caster is also making the attack (which would have also dropped their sanctuary, had it proceeded to the attack roll). The familiar is not doing either of these things - yet it is treated by other game features "as if" it had cast the spell. And in this case, although it did not actually cast the spell, sanctuary treats it "as if" it had, and so sanctuary drops on the familiar as well.
1 It is a bit odd to add a new answer with the same conclusion as a popular answer, 3.5 years after that answer has been posted. In this particular case, I believe that Thomas Markov's answer is right in both its conclusions, but in both cases it uses incorrect reasoning to arrive at those conclusions.