Because of the vagus stimulation which leads to pain relief
Vomiting can stimulate the vagus nerve which can relief inflammation, depression, anxiety, hypertension as well as pain since one of the main tasks of the parasympathetic nervous system is to heal/restore the body after phases of stress. The mechanisms aren’t really clear, but results have been observed quite often already