Our body works on the the principle of ‘need of the hour’. It does not produce or activate anything unless it is required by the system. In case of pepsin, it is an enzyme that is required for digestion of proteins i,e only when you have consumed protein based food.
In the presence of food, both Hydrochloric acid (HCl) and Pepsinogen (inactive form of pepsin) are released by the stomach lining by the action of the hormone Gastrin. Hcl then converts or activates the pepsinogen to pepsin for further action. If these are released in the absence of food, it is possible that they digest your own stomach causing inflammation and ulcer!
Or ith other words ,
Pepsinogen is secreted by the Chief cells present in the stomach wall in response to lower pH, which results from the enhanced secretion of HCl, in response to specific stimuli, such as the parasympathetic response to taste, smell and sight in the cephalic phase, distention in the gastric phase etc.
Exposure to low pH in the stomach lumen activates an auto-catalytic process by which Pepsinogen, a zymogen (inactive enzyme precursor), gets activated to Pepsin. However, pepsin cannot be secreted in the active form.
Secretion of zymogens protects the stomach wall, primarily the chief cells that secrete it, from auto-digestion.
If pepsin was secreted in the active form, it would break down the mucosal barrier and expose the underlying tissue to corrosion by HCl and the proteolytic enzymes, leading to ulcer formation.
Hope this helps! :)