Washer not draining

My washer isn’t draining after the rinse cycle. If I catch it during the spin cycle and open then close the lid, it starts to pump the water out immediately. I usually just find it full of water after all cycles are complete and have to run the spin cycle again to get it to drain. Anybody know what causes this?

Could this possibly be the lid switch? …anybody?