Stall for time while waiting for their leader to die.
Going case by case, the Jin performed the best against the Mongols, then the Song, and then arguably the Koreans, although the Mongols did not give it the same priority as other wars besides 1234. Both the Jin and Song employed a cordon scheme based on a major river+mountain range front, covered by an array of heavily fortified cities. These cities were often dozens of miles wide in circumference, with walls of rammed earth that stretched many meters. Adding on, they used navies with gunpowder weapons to secure the riverfront and quickly ship troops around. The Mongols had great difficulty crossing these large rivers unless there was no nearby opposition. They could bypass the cordon by going to extreme and rare lengths, as they were forced to do by invading the Song in Hanzhong in 1232 in order to then attack the Jin from the south, and invading the Song through Tibet->Sichuan->Dali->Dai Viet into Guangxi in 1258 to attack the Song from the south and west. But these campaigns are obviously very costly and risky, and required generals of rare abilities to make them work.
Once the cordon was bypassed, the second problem was then the large fortified cities in a scorched earth environment. These cities, could sustain armies in the tens of thousands of men and were so wide in circumference that large Mongol forces were required to make any siege possible. In 1232-33 when Subutai defeated the Jin armies in multiple battles, he had full initiative but could not besiege even Luoyang, Kaifeng, and Guide simultaneously since most of the Mongol army was withdrawn. He had to pull back his forces from Luoyang and Guide to focus solely on Kaifeng until most of its troops escaped along the Yellow River using the Jin navy. Only then was the threat of a counterattack reduced enough for him to initiate other sieges. That aspect of the counterattacking threat is something often missed in military analyses of sieges and defensive systems.
The Koreans relied on mountain forts like the Song, and Korea is naturally one of the more difficult countries to invade due to its mountains. They had a great idea of transferring their government offshore to Ganghwa Island, which was simply inaccessible for the landlubber Mongols. So they had to reduce Korean positions one-by-one, and this was exacerbated by the scorched earth tactics the Koreans willingly embraced. Korea was devastated and huge numbers of their people died due to a lack of food but they did delay the Mongols for many years. The latter is a key element: you could effectively delay the Mongols by denying their ability to sustain their forces, especially their local auxiliaries, although it would also ruin your own people in the area. The Jin used this as well and saw the same suffering, and we know that Hungary's population was devastated in 1242 after the Mongol retreat just from the resulting famine which occurred due to the inability to forage the harvest in the fall of 1241 and plant in the spring of 1242.
Castles run into the same operational problem as the mass network of Afghan hill forts even before you talk about the weaknesses of walls etc: they are easy to mask with a small number of troops. Since they cannot sustain large armies inside and often are positioned in difficult to access terrain, that also means they are not a credible defensive->offensive threat. The less of an offensive threat they are, the more easily they can be masked (to starve out) and bypassed without being forced to allocate too many troops, so long as you can supply the invading forces. Castles and hill forts are of course great options if you and your economies are poor or decentralized, since the local rulers can make them with their own resources and a poor enemy won't have the logistical resources to sustain long campaigns. But they certainly aren't a preferred option if you can afford better. That said, a network of castles on say the Elbe or the Danube could have been devastatingly effective at creating a cordon, since its far more difficult to just mask and bypass them then.
What could have done wonders theoretically was the approach the Northern Song used against the Liao: creating a natural barrier on the frontier using vast networks of man-made forests and lakes across several hundred miles of mostly plains. This was extraordinarily successful and economical, but after the Song tore it down they never resorted to it again, instead trusting in the Yangtze and Huai rivers. The Jin did not copy them either. It's not clear that it would have been as effective though because the Mongols seemed to have been far more proficient at campaigning in adverse terrain than other nomads, but its definitely worth mentioning.
All the talk about the Delhi Sultanate or the other post dissolution enemies isn't really notable because the post-dissolution khanates usually fared poorly in offensive campaigns, so victories over them is far less notable than the pre-dissolution armies. To give a rough modern analogy, the Vietnam victory over the U.S. is notable since the U.S. historically fared very well in wars and were much stronger. But if say 6 Vietnam-type losses occurred for the U.S. against a lot of enemies during the 70's and 80's, then it becomes far less special because it is no longer unusual victory or over an otherwise unstoppable power.