The stomach is protected by two enzymes, COX 1 and COX 2 (Cyclooxygenase 1 and 2). These are prostaglandin enzymes. From this article on NIH:
...both COX-1 and COX-2 either alone or in concert contribute to gastric mucosal defence
This is why long term use of COX non-specific NSAIDs can cause severe stomach problems, since they inhibit the production or function of these enzymes. There may be other processes that further protect the stomach from the effects of hydrochloric acid, but I believe these enzymes play the most important roles, especially when one considers the effect caused by inhibiting their function.