I didn’t realise that they got that hot! I’ve learned something new 🙂
I think it’s because, in really heavy, dense thunder clouds, there is loads of static energy. A bit like when you rub a balloon on your hair, or on your jumper, and you get that static attraction, and sometimes hear the sparks of crackling static energy. This is a bit like electricity, as you’re whipping electrons off their atoms, so that they are just ‘around’. When lightning strikes, there is a huge release of all of this energy in one go. As energy cannot be lost, it is converted into another form of energy. In this case, all of that static electricity quickly discharges, like a battery does in a circuit, but all in one go, rather than in a steady flow, and all of that electricity converts to heat. Apparently quite a lot of heat!
I believe that’s how it’s generated, but if you want to know some more, try and find some reading material about static electricity and lightning, or else let me know if it didn’t make any sense!