However, in infants, this sphincter is not totally developed, and thus doesn’t always keep things down. During the normal movements that an infant’s stomach makes, it might push some food up, through the weak sphincter, into the esophagus and out.
In older children and adults, throwing up is usually the result of some specific stimulus (responding to vertigo, disease, bacterial toxins in food, etc). In this case, your stomach is actually working to push its contents back through the esophagus and out your mouth. As such, the muscles in your stomach clench very hard and at the same time, which can be painful.