Swapping sides are given in all outdoor field sports that feature a goal on each end. American football, lacrosse, field hockey, soccer, rugby, etc. The idea is that it can negate certain advantages. The wind behind players may be good to them or against them. The sun in their eyes or at their back. Field conditions on one side of the field or the other side. Outside the pro game, some poorly designed fields may have an incline that tilts toward one side, or perhaps one side of the field will stay wet after a rain, while the other sheds water well.
It can also prevent home team groundskeepers from using tricks such as keeping the grass longer on one end of the field, slowing down their opponents, while making it shorter on their attacking end to speed up the game. It keeps teams honest.
Even in basketball and indoor volleyball, where sun and wind are not factors, teams switch sides. In basketball, it can discourage teams from seating their ardent fans behind the basket on one end. If they do that, they will realize that the situation will change each quarter.
Consider a game of soccer or other outdoor field sport where one team has the wind at their back and the sun in the eyes of the defenders the entire match, one team would have a huge advantage. Switching sides can even that out. It is not a perfect system. Wind direction can change during the game. The sun can become less of a factor as it rises in the sky, or sinks below the tree line. But switching sides is an attempt at fairness.
Even though most answers were about advantages and disadvantages on the playing field another important reason is because of the supporters who want to see their team attacking the goal in front of them. If let’s say an extremely strong team (Barcelona and Real Madrid) faces off against each other, which Real Madrid scored two goals each half, then if the fields are not changed the supporters sitting on the side of Real Madrid’s goalpost will see 4 goals in front of them while those behind the Barca will see no goal.
So even though a match cannot be predicted and said when the goals will be scored as all goals can be scored in one half, the idea is that supporters must see their favorite team in front of them.