To show as to why China retreated. Let me try to answer from China’s point of view,
The Chinese Army or what is called The People’s Liberation army retreated mostly because it had met its war-time objectives. The idea never was a large scale occupation of Indian territory. The PLA had reached its claim lines i.e the traditional Macartney-Macdonald Line and had pushed back the Indian encroachment.
The Chinese had intentionally planned a rapid Indian strike strategically timed between the relief in the Taiwanese corridor and the Cuban crisis. Popular Soviet and States support meant that China couldn’t afford to be dubbed an aggressor. Also the Chinese feared for its war supplies against the approaching winter.
The aggressive India forward policy initially aimed at cutting down the supply lines of the Chinese outposts allegedly south of the Mcmahon line, eventually became a expansionist instrument with the backing of nationalistic propaganda, wherein Indian flanks started creating outposts way north of the Mcmahon line.
The Goan liberation had boosted the Indian morale. The forward policy and the Goan aggression, along with open Indian support of the Tibetan cause had made Chinese believe that Indians harbored expansionist ambitions in the North. Later, the Chinese premier, Zhou Enlai unofficially suggested that India drop its claims to Aksai Chin in return for a Chinese withdrawal of claims over NEFA. Adhering to his stated position, Nehru believed that China did not have a legitimate claim over either of these territories, and thus was not ready to concede them. This adamant stance was perceived in China as Indian opposition to Chinese rule in Tibet.
With a swift and decisive blow, the Chinese made it clear of its integrity with Tibet. Showing the world that Chinese forces were still prepared to go back 20 km north of the illegal Mcmohan line in the eastern sector earned China much needed goodwill, specially in South-Asia. It helped China in its argument that it never really wanted a war and was just defending its interests.
End
Even though China won a major military victory, it lost in terms of its international image. Consequent nuclear weapon test in October 1964 and its support of Pakistan in the 1965 Indo-Pak war tended to confirm the American view of communist world objectives, including Chinese influence over Pakistan. Though China accomplished all its war time goals, India hardly lost. As an eyeopener, the military changes, war led to, were humongous which strengthened India not only in terms of military strength but also led to a new surge of patriotism and unity.