Given that these store-bought panels are being plugged into house AC, it follows that they have built-in inverters. Many grid-tied inverters are “grid follow”, meaning that they adjust themselves to grid frequency/phase. So, just speculating here… maybe the inverter senses when the mains go down and turns itself off? I would love to know from an EE what is actually happening wrt safety.