Why do people spit up blood?

Many possibilities. The most common cause of hemoptysis (coughing up blood) is bronchitis and tearing of small blood vessels that line the airways. Other infections can do it as can blood clots (pulm embolism), inflammation of the lung and cancers of the lungs. A chest x-ray is often very helpful to determine the source of the bleeding.
Many causes. There are many causes for spitting up blood, including nose bleeding, dental or oral pathology. It may be coming from the airway as in coughing up blood (hemoptysis) or coming from the GI tract as in vomiting blood (hematesis). It would be best if you see your doctor for this problem.