Why does a mouth ulcer hurt so bad?

Exposed nerves. An ulcer in the mouth is painful due to the exposure of nerves in the ulcerated tissue.
Nerve endings. The mouth has a highly dense area of sensory nerve receptors for pain in the tissue and when you have an ulcer they are exposed and can be stimulated easily.