It's partially an unconscious "system" neurochemistry thing, it literally relieves anxiety/psychic pain:
http://www.ncbi.nlm.nih.gov/pubmed/15576335
http://www.dandsassociates.net/healt...elf_injury.htm
Chewing one's fingernails to the quick so they bleed is a form of self injury, "why" does anyone do that? It's the same dynamic going on.