I am playing dota2 (100h+) and I still do not get what are the circumstances which lead to be targeted by the enemy tower.
What causes the tower to attack the hero instead of the creeps?
The towers will attack enemies in this order:
The tower will switch targets if:
Last one is a weird mechanic that got greatly exploited during last few months,if you get targeted by the tower and click attack button and click on friendly creep the tower will start attacking the next target as if you got out of the attack range.It is getting its popularity since it enables you to attack tower with minimum interruptions(running away+running back from the tower range).To me it looks like a major bug since it makes no sense as a mechanic.
The thing that you mostly experience during the game is that you move inside the tower range (while it is attacking another unit), and then click attack on an enemy hero, which will make the tower attack you.
There are one important method to reaggr tower. If you attacked by enemy tower and allied creeps present near the tower, you can reaggr tower by press 'A' (Attack) and click on allied creep.