Why most of friendly npc in the villages can not be damaged, but some CAN! For example, I have found a Hylotl town with three buildings, and those who live in the first one are immune to my attacks but the others take damage and react with dialogues and behavior (civillians flee, guards fight). How is this defined?
It depends. If you stole objects or killed one they will become hostile. You can kill all NPCs(except the ones found at the Ark/Outpost, because you can't place blocks) by placing lava under them.