You have a qualitative description of what happens, but let's break it down to a smaller scale. When we talk about "temperature" of something, we are really talking about how fast the molecules are moving around and bouncing off each other. "Temperature" is really "kinetic energy". And it turns out that there are other types of energy besides moving around in space -- molecules can rotate, they can vibrate, and their electrons can get excited and move around relative to the nucleus. Each of these energies can also be a "temperature", so you can have translational temperature (what we normally think of), but you can have rotational temperature, vibrational temperature, and electronic temperatures. 

Molecules exchange energy with one another by colliding into each other. When they do this, they also distribute the energy between them. How often they collide determines how quickly the energy becomes uniform, and this defines how quickly they reach what is called equilibrium. When all of the different temperatures are the same, the state is in equilibrium and we don't need to worry about keeping track of all of the different types of temperature. For most of the processes that would occur in an engine, there is more than enough time to reach equilibrium and so we don't need to worry too much about non-equilibrium effects.

Now, in chemical reactions, molecules break apart and form new ones. If the new ones have less energy, the difference in energy is released as heat. If the new ones have more energy, the reaction requires adding energy to make it happen. Obviously engines get hot, so the reactions in them release energy and we harness that energy to move the vehicle. 

So, molecules break apart. And they break apart when they start vibrating so hard that the bonds between the atoms cannot hold them together anything. The only way to make the molecule vibrate is to have another molecule collide with it, with enough energy and an efficient enough transfer of energy to start the vibrations. And the energy has to be high enough that the vibration makes the molecules fall apart. 

By changing the amount of fuel in the mixture, you are changing the types of collisions that can occur. And it's not exactly straight forward, but some molecules are better at exchanging energy with others. To make the fuel molecule fall apart, they need to collide with other fuel molecules with some energy of with other oxygen molecules with more energy. If you add more than the usual amount of oxygen (run lean), you also need to make that oxygen hotter so the molecules have more energy when they collide and can make the fuel vibrate hard enough to fall apart. Conversely, if you run fuel-rich, you have more fuel molecules that can collide with one another and fall apart, but fewer oxygen molecules for them to combine with and give off heat. This (and some other effects) makes the final flame temperature lower.