Quoted By:
That used to be necrozma's true form but it lost it's light after he got injured by getting hit by a meteor. Without it's light necrozma suffers constant pain which makes it very hostile. It now constantly tries to restore it's light by stealing from others, notably stealing from SM box legends to become dusk/dawn forms. But SM box legends are the light of Alola so if their light got stolen Alola will fall into darkness which is why you need to kill him and take back the box leggy. Eventually it's discovered that performing Z-moves are basically a trainer giving his "light energy" to temporarily power up the pokemon, which is why he can temporarily turn back to his true form via a Z-crystal.
That how it was in the anime at least but iirc he has a similar lore in the games though the didn't do a good job of explaining it to you