You might think that water should just travel one direction in the sewage pipes leading away from your home, and that is downstream, but a municipal plumbing system is a little more complicated than that. For example, if there is a major drop in pressure for some reason, maybe due to a large leak or a fire hydrant being used, this can lead to something called backflow. To compensate for the sudden drop in pressure, sewage water is actually sucked back and could end up inside of your home if you are unfortunate.
Events like this are the reason for a device called an atmospheric vacuum breaker. It could be that you have noticed one of these if you see a pipe that is overground, but coming out of the ground and going back down.
The way it works is that the atmospheric vacuum breaker will allow air into the pipe in case of backflow, and this will break the suction that is pulling sewage water back in the wrong direction.