The Player's Handbook gives a concise rule for when you know a spell has been cast. From Chapter 10: Spellcasting, in the section entitled Targets:
Unless a spell has a perceptible effect, a creature might not know it was targeted by a spell at all. An effect like crackling lightning is obvious, but a more subtle effect, such as an attempt to read a creature's thoughts, typically goes unnoticed, unless a spell says otherwise.
Is sanctuary a perceptible effect? Sanctuary says:
Until the spell ends, any creature who targets the warded creature with an attack or a harmful spell must first make a Wisdom saving throw. On a failed save, the creature must choose a new target or lose the attack or spell.
While the target creature is not being attacked, the effect of sanctuary is definitely imperceptible - the spell itself isn't really doing anything for you; there is no effect to perceive.
What happens when a creature tries to attack the santuary target is going to be up to the DM's narrative interpretation of the spell description. Does the targeting with an attack take place entirely in the mind of the attacking creature, or does the attacking creature begin the motions of the attack before suddenly changing course and attacking someone else? This is entirely up to how the DM wants to describe the wisdom save and the declared attack.
As a DM, I would rule that the attacking creature begins the motion of the attack, then makes the saving throw. On a failure, it appears to the warded target that the creature stops mid attack and changes direction or just stops the attack entirely. In this case, if the warded creature is aware that their buddy can cast sanctuary and is somewhat familiar with what sanctuary does, it would be totally reasonable for the warded creature to think, "Ah, I must be warded by my cleric friend".
A DM who goes for a more subtle interpretation may rule that the warded creature just seems to be targeted a little bit less than before the spell was cast, which itself may be an entirely impercptible phenomenon. The trouble with this case is that the resulting state of affairs after the spell is cast on you may be entirely feasible if the spell was not cast on you. Even if sanctuary is cast, the resulting enemy behavior is a possible outcome even if the spell was not cast, so the warded creature may not even notice.
Perceiving a Caster at Work
As a DM, I would usually have no problem allowing a player to simply know they have been warded by sanctuary - and I have reason to believe it is not any sort of metagaming.
Xanathar's Guide to Everything1 has a section called Perceiving a Caster at Work that helps our warded creature know something is up even if the effects of the spell are entirely unnoticed:
To be perceptible, the casting of a spell must involve a verbal, somatic, or material component. The form of a material component doesn’t matter for the purposes of perception, whether it’s an object specified in the spell’s description, a component pouch, or a spellcasting focus.
Notably, Sanctuary requires verbal, somatic, and material components. Verbal and Somatic components are described in the PHB in chapter 10:
Most spells require the chanting of mystic words. [...]
Spellcasting gestures might include a forceful gesticulation or an intricate set of gestures. [...]
So sanctuary contains unique words and hand gestures that would likely be identifiable by an observer - especially if the observer is familiar with the caster.
Now, Xanathar does include rules for identifying a spell being cast:
... a character can use their reaction to identify a spell as it’s being cast, or they can use an action on their turn to identify a spell by its effect after it is cast.
If the character perceived the casting, the spell’s effect, or both, the character can make an Intelligence (Arcana) check with the reaction or action. The DC equals 15 + the spell’s level. [...]
This Intelligence (Arcana) check represents the fact that identifying a spell requires a quick mind and familiarity with the theory and practice of casting.
There is a way, per RAW if you use the Xanathar's rule, to use your reaction to identify a spell being cast. But I did say before, "especially if the observer is familiar with the caster". To be clear, this is a DM ruling that I would make that technically departs from the RAW, but I would allow my players to identify spells being cast by their allies for free.
Your allies are familiar with your style of spellcasting. They see you casting these spells day in, day out. To this DM, it seems entirely feasible to know what my cleric friend's casting of sanctuary looks and sounds like. And this is easy enough to justify with some roleplaying:
Cleric: Hey guys, I have this spell that will protect you in a pinch, but you can't attack or cast spells at the enemy or the effect wears off.
Party: Good to know, what do we need to look out for when you cast it?
Cleric: If I says these words and wave my hands around like this and gesture toward you, you've been warded and need to chill out on attacking the bad guys.
Having established this, I would simply allow my players to always know they have been warded by sanctuary, unless for some reason they miss the casting of it entirely.
1Notably, XGtE is optional source material, so it is up to the DM to make use of it or not.