Eventually, it encounters something on the ground that is a good connection. The circuit is complete at that time, and the charge is lowered from cloud to ground. This entire event usually takes less than half a second. Most electrical and electronic damage in off grid and solar systems is NOT due to a direct hit. In fact, direct hits are rare.
Most damage occurs from nearby hits, usually within a few hundred feet.
A near-strike can induce thousands of volts onto the house wiring if not protected. In a ground hit, it can also spread out and travel into buried conductors, such as pipes. Contrary to popular assumption, the panels themselves are not the biggest victim - inverters and controllers are. Also, the battery banks on most systems acts as a fairly good surge arrestor if you have good connections - but it may take out the controller on it's way. If the battery bank is not grounded, damage can be much more severe - it may then leap around all over trying to find a path to ground.