Why did China went with this agreement though? They hold all the cards here and it simply doesn't make sense, The concessions India got are just too generous
The situation there is fuzzy, with the exact details hard to come by. I see members here arguing back and forth who wins more favorably with the disengagement. I view them more as psychological squabbles without knowing many of the details.
While the exact details are difficult for us to know, it's relatively easier to assess the picture at higher levels. There are two levels here: one is at the overall tactical positioning at the border, the other is at the national strategic level. I believe in any agreement reached without actually fighting a war, both sides will need to compromise. China will gain some of its key objectives, but it will also need to give India concessions. For China, the objective is not about a particular location of contention, but the overall positioning and posture afterwards.
China's goal in the current maneuvering was not a complete victory over India. It was really to counter some of India's aggressive moves and serve to warn India that their aggression was counter-productive and will be met with counter-measures. China's overall goal with India is to have a stable even if not friendly relationship; it's not about humiliating India or conquering large pieces of land, which would be at huge cost without actually gaining much strategic benefits. India is not China's priority, unless it provokes and pushes to escalate to be so.
Therefore, the rationale for the current disengagement from the Chinese side is partly in your question: that China has moved against India decisively and has demonstrated its position of superiority ("they hold all the cards here"). Now it can show its magnanimity and "generosity" - because it can afford to do so from a position of strength and it is consistent with China's larger strategic goal. China wants to focus on dealing with the US in the east, not to be bogged down with India on the border in the west if possible.
It's a very Chinese way of thinking. After the 1979 Sino-Vietnam border war, China and Vietnam continued to have sometimes fierce border conflicts well into the late '80s. It occupied some of the strategic mountain tops presumably belonging to Vietnam. The border conflict was a minor nuisance for China limiting to remote border region but a big burden for Vietnam economically and militarily. With the collapse of Soviet Union which was Vietnam's treaty ally and patron, the isolated and impoverished Vietnam wanted a way out. Its leadership requested and got a high-level private meeting with Chinese leadership in Chengdu in September 1990. Chinese President Jiang Zemin and Premier Li Peng and the full complement of Vietnamese leadership attended the meeting. The next year, Vietnam's top leaders paid an official visit to China and the two countries normalized the relationship, ending the 13-year hostility. China returned the mountain tops it occupied during the conflcits to Vietnam after the two countries demarcated the land borders later. Vietnam today is a thriving economy with GDP per capita much higher than India's, and with China being its largest trading partner even though it continues to have conflicting territory claims in South China Sea with China.
There is something for India to learn from Vietnam's experience. I understand many Indian elites would scorn at such idea, believing it is (projected to be) a superpower, not a poor third-world country like Vietnam, and as such demands China treat it as a superpower (that it might become in 50 years). But still.