hi, interesting question!
physically, pain is the result of nociceptor activation in the peripheral nervous system, as far as I understand it.
mentally, i'm unsure but identification with certain thoughts can trigger an emotional response that mimics the physiological fight or flight response
of course, pain is part of the dream. no more important, nor less valuable than anything else in the dream. Apparently, it's a necessary evolutionary phenomenon for the survival of all species (plant life included).
again, it's also not real