The main rationale for building the Great Wall of China was that it would provide defense for the Chinese empire against enemies from the north.
For much of Chinese history, the main external danger to the empire came from the north. This is where the Mongols lived. They periodically raided into China, causing major problems. In the late 200s BC, the emperor Qin Shihuangdi started to join together individual stretches of wall that had been built for defensive purposes in the north. The wall as we know it was built over a thousand years later. In between those times, walls were built and rebuilt.
There are said to be other purposes for the wall, such as serving as a way to regulate trade with areas outside the empire. But the main purpose of the wall was defense.