If you attack move close to a wall, moving ranged units in from a distance, as soon as they ‘see’ the enemy but aren’t in range, they’ll walk away looking for the nearest gate/way around instead of moving closer to the wall to start shooting. In order to actually start attacking over the wall, you have to manually move them within range of the enemy units and then attack in order for it to work. I think they’re acting like melee units once they have vision of the enemy.
here it is on imgur: ranged unit bug aoe4 - Album on Imgur