When we are under stress we tend to lose our appetite, but when we get away from the stress and start to relax physically and emotionally, our appetite returns and we eat. Often, for physiological reasons, our body craves certain foods that are rich in fat, sugar and salt, which leads to us eating inappropriate food and too much of it.
We feel comfortable because we are away from the stressful situation but our brains can become confused and conflate the feeling of relaxation with eating unhealthy food, leading to comfort eating. Ultimately, our brains are confusing two different situations, as all the evidence is that eating unhealthy food is not good for stress, whereas in the long term a healthy diet is beneficial for stress.
The same thing happens with smoking. There is no evidence that smoking helps stress in any way, but people tend to have their cigarette once they are away from the immediate source of their stress, when the body is starting to relax. Again, the brain puts two and two together, and comes up with five.
Stress is a medical condition and it can have a serious effect on your health. If you think you are suffering from stress it is crucial that you consult a medical professional.