Sometimes units inexplicable run away from their targets before attacking.
What happens in this case is in unit motion they TryGoingStraightToTargetEntity where they then find NearestPointOnGoal. However, that only selects points on the boundary of the goal area and doesn't take into account that the unit might already be inside of it, so instead of just stopping they turn around and run away from the target to get to that "nearest" point.
If some part of the code wants to avoid some area then they should be using the inverted goal type.
History at rP7484 as well as rP8751 for TryGoingStraightToTargetEntity and rP16751 for inverted goals.