DIAGNOSIS You have a faulty or loose connection on the main control board's memory circuit. A brief power dip is causing a reset.
FIX Check the house wiring first. The microwave should be on its own dedicated circuit. Having it share a circuit with lighting can cause brownouts when switches arc. An electrician may need to check the circuit.
IF THAT DIDN'T WORK The main control board has a failing capacitor that maintains memory. The board, part WB27X11334, needs replacement. This is a common failure mode.
HEADS UP Constant resetting can corrupt the board's programming. If other functions start acting erratic, the board is definitely bad.