At the time, China was under complete influence of communism and is allied with the west. It would be no surprise that they are willing to support a fellow communist state that is neighbouring their border.
The US supported South Korea because they were opposed to the communist belief that was in North Korea. In fear of communism spreading further, they opted to aid the south.
China also feared that the south forced, together with the US, will take over the North and continue to advance towards China. For explanation, China only sent in their troops once the south reaches china’s border.
If the south was taken over, the communist forces could very well take arms to Japan. Fearing the lost of Japan, which was a huge economic slump and trades partner to the US, the US decided to reinforce their army to the south.
Hope this helps!