I'll try to briefly summarize this.
Exhaust gas temperature (EGT) depends on combustion temperatures. The hotter the mixture burns inside the cylinder, the hotter it will be coming out. Theoretically, combustion temperatures are at a maximum at stoichiometric, but realistically the maximum occurs slightly rich from peak because of the dissociation of Oxygen from the combustion products (CO2, H2O). Why temperature drops when rich or lean is described by the energy released caused by the chemical reactions between the fuel and air. Too little fuel (lean) and there is less energy contained within and more heat is transferred to the cylinder walls (no fuel evaporation or boundary layer), thus the lower temperature when it burns. Too much fuel, and combustion efficiency drops thus generating less heat.
I know, this is not too detailed, but it gets the point across without involving too much technical jargon.
Of course, this all assumes MBT timing and stable combustion. You can also change exhaust temps by varying spark timing, arguably moreso than by just varying AFR. EGT is increased when spark timing is retarded since you are giving the gasses in the cylinder less time to cool off before the exhaust valve opens.