I experienced something similar except it would happen when I was looking at my inventory, equipment, or if I was trying to read books and letters. While the interface was changed so that I could see my inventory or book nearby "friendly" NPCs would suddenly turn hostile. This is why I had to kill Scratch...