So this question has been on my mind for quite some time.
Imagine this. I'm pushing a lane. I'm all alone, and the two groups of creeps approch each other, and I just auto attack away on the enemy ranged creep.
The enemy ranged creeps gets to about 20% health, and this is when suddenly ALL MY CREEPS surprisingly stops attacking the melee creeps they were attacking before and starts attacking the enemy ranged creep like me?
What is going on here. Why do you suddenly start attacking the ranged creep instead?
The enemy ranged creep probably started attacking you when he was low(because the target he was attacking before died). Since attack priority for creeps is #1 when a nearby hero is attacked, your ranged creep has become your (allied) creeps primary target.
TL;DR:
Your creeps attacked the ranged creep, because the ranged creep attacked you.