Mobs will always attempt to face the direction of where they received damage from, effectively trying to run into you when you try to hit them, works with any mob.
Mobs that don’t panic when hit only do this when they are moving already, e.g. in wander mode
I think I’ve reported this before, but it seems to have disappeared or went missing somewhere idk
extra info : The “franticness” of the mob also affects this, which means villagers (probably the most frantic) will do this less often, because they go frantic and pick a random direction to run in a lot more when panicking.