The decision to cross the 38th parrallel is correct. If China had hesitated, the U.S. would take it as a signal for weakness and spread the war to China. It was not long since U.S. aided KMT in the civil war. The American military existence in Korea, Vietnam and the Taiwan Strait constituted a containment of PRC. The newly established PRC needed to prove its determination and strenghth to protect itself even from the mightest military power.
The worst result of the U.S. occupation of all of Korea was not a U.S. invasion of China, rather, it was a U.S>S.R.-U.S. war being fought on the soil of China. In such a situation, the two super powers would probably reach some cease-fire agreement at the cost of China. The memory of the 1904-1905 Russo-Japan war was as fresh as had taken place the day before. China and Korea fell victim to a war between two imperial powers. PRC should not allow that happen again. The loser of this war is Koreans.
The decision for the PVA to cross the 38th was certainly flawed:
- Mao made the same mistake as Truman made earlier when he authorized MacArthur to liberate North Korea.
- Mao underestimated UN firepower when he believed the UN coalition could be kicked out of Korea. The more he pushed the PVA to the south, the more logistics problems they faced and the greater the UN resistance. The guerilla tactics that worked so well for the PVA in the beginning against a thinly stretched and disorganized advancing enemy was completely useless against static, well-prepared, extremely closely knitted lines of UN defenses (which they had time to construct while the 8th Army fought a delaying action against the PVA in their retreat).
- US main strategic interests still lies in Europe, particularly Germany. They have no interest to fight a long protracted war against China for the sake of reunifying Korea under a democratic government. As Omar Bradley said, the Korean War was in the wrong place and against the wrong enemy.
P.S. The US never had any intentions to invade China, encircle yes, but not invade. MacArthur wanted to, but he does not represent US government foreign policy. He got sacked for trying to play as a politician against Truman as a result.