unkillable mobs

/summon ExampleMob ~ ~ ~ {Invulnerable:1}


You could give the player a really strong weakness status effect if they're within melee range of the mob. This isn't exactly what you're looking for, since the player won't be able to kill any mobs within that region, even ones that they normally would elsewhere. If you're fine with that, then go right ahead.

If you also want it to be immune to player-shot arrows you could add

execute at @e[tag=enemy] run kill @e[type=arrow,distance=..2,nbt={pickup:1b}]

This only affects arrows shot by someone in survival or adventure mode, and not in creative. It also ignores arrows from entities like skeletons or pillagers.