It is to stop the fuel cross flowing into the opposite wing. If I park mine left wing down and don't turn the tank off then the fuel flows across and out the vent. I can tell you from practical experience you lose rather a lot of fuel if you don't......
You don't fly 172's switching between tanks, they are always flown with BOTH to on unless there is a need to settle a fuel imbalance and that is only done in cruise flight.