China is North Korea's largest trade partner as well as their main contributor to foreign aid, it is clear that they are allied to/friendly with North Korea
What does China have to gain by being allied to/friendly with North Korea?
China likes a barrier between US-allied territory and itself. Before North Korea was the nuclear threat it is today, it was the barrier that the Chinese government wanted.
And I think that China believes that they can make North Korea back into the (somewhat) peaceful 'barrier' if they keep giving them aid and buying stuff from them. Or at least they believe that North Korea won't attack them if they stay 'relatively friendly'.
China may also see solidarity with North Korea regarding shared hardships that both of them have gone through, such as WWII Japanese occupation, or US embargoes during their socialism days.
Another possible reason is that apparently China is fearful of refugees fleeing North Korea and going into China if the Kim regime falls. In that regard, they'd rather preserve the status quo, though they'd definitely rather turn North Korea into the 'barrier' again.
It is as simple as in the relations of the enemy of the enemy.
Looking back at the Korean War, it is not difficult to find the war might have been extended to China if it had not been limited in North Korea. That is the reason China began their assistance to that country. Then came the Cold War, when communist (socialist) countries and capitalist countries formed their respective blocs, and since North Korea and China are self-claimed socialist countries, they have to bond together to establish their images to the world.
In today's China, young people who are influenced by western cultures not less than those who live in the west do not like North Korea as does their own government. And time and again China has felt the small neighbor is out of its control. Kim Jung Un hasn't even paid a visit to China since he came into power 5 years ago, and the distance of the two countries is so close.It is obvious that he does not respect China but that China has no other better approach for the time being to handle this country than maintain the existing relationship.
What CCP gains with N Korea? (CCP is not China and China is not CCP)