Zombie Pigmen attack on the basis of 'seeing is believing', meaning that they only become hostile when they see one of their own being attacked by you. Once this happens, all Zombie Pigmen within a certain radius (32 blocks) become hostile, and will charge at you if they are within range. Zombie Pigmen will also notice attacks through walls.