It's not broken, that's exactly how it's designed to work. The default targeting behavior bound to Tab is to cycle through enemies based on distance, from nearest to farthest. With an enemy targeted, it's always going to keep targeting further and further enemies until there is no enemy farther away from you, and only then will it start targeting enemies close to you.
If you want it to cycle through enemies from far-to-near instead, you have to use /target_enemy_prev (bound to Shift+Tab by default), and if you want to force it to target the closest enemy, you need to use "/target_enemy_near" (bound to Ctrl+Tab by default).