According to my understanding, lightning happens because the clouds get charged due to friction from the moving clouds and the ground gets polarized by the nearby charged clouds. And the two opposite charges cause a huge electric field in between them that’s strong enough to break down an insulator like air itself which we call lightning.