Why does the overflow happen only with the washer running?
An intermittent overflow can reveal a problem that is not apparent when no appliance is discharging. A restriction, installation issue or receiving-drain limitation may be involved. Observe whether water comes over the top of the standpipe or escapes from the hose or a nearby fitting. Those are different repair questions.