I thought everything is in the brain.
Why do we feel pain in our stomachs when we are sad?
I certainly wouldn't say "everything is in the brain"; even the central nervous system is defined more broadly than that (to include the spinal cord)...and then there's everything else in the peripheral nervous system to consider...
I also wouldn't say that feeling pain in one's stomach when sad is normal (you didn't say this either, but it's implied by your phrasing, so I think you might've assumed it), but this and the many other varieties of somatization aren't necessarily abnormal either, in as much as it may occur for most people in some way at some point in life (an intuitive guess informed by personal experience; don't quote me on this). From Wikipedia: "Somatization is a tendency to experience and communicate psychological distress in the form of somatic symptoms," which includes bodily pain of pretty much any variety. Note that this definition raises some interesting questions, e.g.:
Setting these aside and assuming sadness is your original source of stomach discomfort, there are a number of ways this could occur, and the stress of strong negative emotion (which includes sadness) could exacerbate it. Stress in general can cause ulcers (e.g., stress from head injury; Li et al., 2010). Here's a good (and very long) section from The Cortisol Connection (Talbott & Talbott, 2007) [bolding added]:
Pardon the wall of text; I could hardly shorten it further without cutting out directly relevant material or supportive explanation of the responsible anatomical mechanisms. Anyway, given that sadness (a form of stress) can cause our stomachs to go haywire when it's intense or chronic enough, haywire stomachs can then reduce energy and well-being, which forms a wicked little feedback loop between emotional and gastrointestinal distress. Feeling stomach pain can also cause one to clench the abdominal muscles, leading to cramping, which itself also leads back to pain and stress, so that's two feedback loops! Severe and chronic stress can also lead to rumination among those without better coping mechanisms, which is another cognitive-emotional feedback loop unto itself: the more you worry about your stress (both emotional and physiological) is the more you have to worry about!
Given at least these three, distinct, vicious cycles, it's not hard to imagine how a person can spiral out of control and into true disorder. Somatization disorder (SSD) is one such possibility; pain disorder is another. Both involve physical pain that is largely, sometimes completely caused by psychological stress, and are sometimes comorbid with mood disorders, among others. SSD is also sometimes comorbid with IBS.
Extreme cases might best relate to the sentiment expressed in your question, but that doesn't mean your case is extreme or even abnormal necessarily. If you or anyone else is concerned that you might have a disorder such as pain disorder, SSD, IBS, or if you're in any way concerned about how depressed you feel, I'd encourage you to talk to a counselor or therapist (some help is even available for free), seek diagnosis only from licensed professionals, and focus on what you can do about it instead of how bad it might be right now. Most psychological problems can at least be improved through patience, persistence, and positivity, so don't worry about labeling your problem or yourself; focus on finding and pursuing improvements and hope.
Here are some ideas that may help break feedback loops that exacerbate psychogenic stomach distress:
Li, Z. M., Wang, L. X., Jiang, L. C., Zhu, J. X., Geng, F. Y., & Qiang, F. (2009). Relationship between plasma cortisol levels and stress ulcer following acute and severe head injury. Medical Principles and Practice, 19(1), 17-21.
Talbott, S. M., & Talbott, S. (2007). The cortisol connection: Why stress makes you fat and ruins your health - And what you can do about it (pp. 120-122). Hunter House.
Coming in super late to this one, but I think Nick's answer only gets at one side of the equation. He's suggesting that sadness might cause stomach pain (somatization), which is likely true.
However, it's also possible that stomach pain causes negative affect (in a non-trivial way, independent of the affect associated with the pain itself). That is, stomach pain represents an allostatic (cf. homeostatic) deviation, and affect is the mental representation of that deviation. So if something bad is happening in your body that your brain does not predict, this is represented mentally as negative affect. Indeed, that's the function of affect--to represent bodily allostasis and motivate action to maintain it.