When the fight or flight response is activated, a number of hormones are secreted into the blood stream. One of them is adrenaline, which gives you the energy to stay and fight or run and flee.
However the logic behind eating in response to stress is less clear. If I think about myself, I am usually quite tired and want a nap after stuffing my face with food - which sounds like the opposite of what you'd think would happen when you are stressed and need to either fight or flee from the threatening situation.
However, when stressed, cortisol is also released from the adrenal glands which tends activate your appetite about an hour later.
Also, another possible link may be that cortisol interacts with signals that control your appetite and feelings of satiety. And other finds suggest that cortisol could also result in your brain finding more pleasure if sugar foods.