When stomach secretes hydrochloric acid naturally to promote digestion of food, then why do we complain about acidity? Any disturbance in the natural process results in a disorder or disease in the body.
When we eat a meal, the food enters into the stomach through esophagus. The esophagus connects stomach with a circular muscle called lower esophageal sphincter. This sphincter allows the movement of food from esophagus to stomach, and restricts the reflux or backward movement of stomach contents into esophagus.
In heartburn, the lower esophageal sphincter fails to restrict the back flow of stomach contents into esophagus in turn we experience burning sensation in the esophagus. The esophagus is not lined with the specialized, acid-resistant mucous layer that protects the walls from the low pH of gastric acid. Therefore, we experience severe heartburn when the acid enters the esophagus.

Several other factors that trigger the acid secretion in stomach causing acidity include
Imbalance in the daily food plan: Usually we follow a particular timetable for eating food.Sometimes we break the time table because we are busy with some work. However, out of habit and as the sensation of hunger arises, the stomach starts secreting gastric acid. Without food within the stomach to digest, we begin to experience acidity.
Stress, diseases and overeating also cause acidity in the stomach.
Consumption of alcohol, eating spicy foods, smoking, and obesity develops acidity
Drugs: Some drugs like painkillers tend to inhibit the prostaglandins that protect the stomach from the acid. In addition, some drugs have the ability to damage the protective stomach lining. Due to lack of protection to the stomach, we experience acidity.