The water droplets in a cloud are rising and falling all the time due to the air currents and pressure differences. This jostling about means the water drops rub against each other a lot (friction). This friction transfers electrons to and fro, so the water gets charged up with static electricity. Over time you get an accumulation of positive charge at one end of the cloud and negative charge at the other end. If the stored charge gets too large you get an electrical breakdown: a lightning bolt ⚡!