You can also run into this with bandits, after they kill you, they greet you.
Worse if you drop something while sneaking next to an bandit, you risk that he ask politely if he can keep that you drop.
Happened to me, dropped some weapons for Lydia to carry, an bandit next room came over and asked for it.
This happens because the game has one combat AI who decides how to fight and one everyday one who handles schedules and interact with other npc and the player.
If the player is sneaking or dead the npc is not in combat

)