I read in my book that during digestion our stomach secretes hydrochloric acid ($HCl$). Why we do not get hurt from it? It was also said that mucous provides protection, but from where is it coming?
These are specialized epithelial cells whose job it is to produce mucins. Mucous role is not only important in protecting the epithelium of the digestive tract from HCl, it is also a very important substance in the innate immune system, acting as a barrier defense to trap pathogens and/or prevent them from breaching the epithelium and gaining access to sterile parts of the body.
Our stomachs are lined with a special mucal layer which protects the organ from its own secretions. People with stomach ulcers have a hole in this layer, allowing the acid to get to the skin underneath. HCl is present in our stomach to aid digestion - especially with dismantaling the bolus (food) coming from the oesophagus. The HCl separates the larger bolus to more smaller pieces. The stomach has a mucus which protects the tissues from being damaged. People with gastric problems may not have a sufficient layer of mucus to protect their tissue and the pain is from the acid eating through the tissue. Thus, a common solution for people who have Gastric problems is to use tablets which neutralizes the acid so that it is weaker.
Simply, it's because of the mucous layer around the stomach, that prevents the strong acid, HCl to hurt our stomach. Not only this, if there were no mucous, the HCl would digest the protein present in the epithelial cells, so the stomach itself would get digested. So the main protagonist here is the mucous layer.