It was primarily built to create a geographical barrier where otherwise there was none. Even though all such barriers can in principle be crossed or bypassed, they can still cause considerable tactical and logistical issues for any attacker.
Without the wall, raiding bands of any size could just slip through and cause havoc. Only large and well-organized forces had siege equipment to break through wherever they wanted. Similarly, traffic and migration of peoples could be controlled and tolls and customs could be enforced. It also acted as an infrastructure for fast transmission of messages. In those ways, like the Roman Limes and the European castle networks, it was mostly an infrastructure for peaceful times.
But even in war, it was preferred to bypass it or to capture a gateway fortress, otherwise these forces could cause enormous problems for the attackers. For example, only allying with the Ming garrison at Liaoning made it possible for the Manchus to crush the short-lived Shun dynasty and establish the Qing dynasty.