Kim and his regime hold onto power by amplifying the conspiracy and rhetoric that the country is ever-under the threat of destruction by the "West". Their entire propaganda machine revolves around not only the power and infallibility of the Kim dynasty, but that if they aren't ever-ready for the impending invasion by the US and its allies then Donald Trump and his evil minions will wash over the shores of their eastern seaboard and take the country from them.
Kim's (and his fathers, and his grandfather's) posturing is designed to continuously provoke a response from the US. The more footage he has of the president and other world leaders condemning him and his government, the more footage he has available to spin into propaganda. The stronger the rhetoric from the west, the better the propaganda.
Trump is feeding this machinery, giving the regime beautiful full-course meals of sturm und drang to serve up to the public. They need not twist or manipulate his words/meanings. They are overt, blatant statements filled with "fire and fury" that can play over and over to reinforce the internal propaganda that the country is ever on the precipice of invasion or destruction.
Kim is continuing to pursue his own form of twisted legitimacy. A country surrounded on all sides by enemies or, at best, frigid allies, needs to perpetuate an core of strength and power. In his mind, continuing to pursue his nuclear and missile regime works on two fronts - firstly it continues to provoke his "enemies", whose bellicose responses feed back into his propaganda system. Secondly it helps perpetuate the internal and eternal myth that he is doing all he can to protect his nation from it's enemies. By throwing up missiles, he creates the illusion of power, strength and defiance to feed to his subjects, and he generates the media and political reactions necessary to continue to feed into his myth making.
Kim does not have a strangle hold on power in NK. He is not the "Dear Leader" that his grandfather was. So he needs a power-play that will keep him atop the throne. He has ruthlessly either executed, or simply assassinated, many parts of his government (and own family) to shore up his power within his government, but to continue to instil the fear in his people (and generally attempt to attain the adoration that Kim Il-sung basked in for 50 years), he pursues nuclear technology. It gives him a (false) sense of status in the world and backs up his promises to the nation that he will protect them from the West at all costs.
Kim is endlessly written off as crazy. He certainly is morally and ethically disgraceful, but his tactics continue to work. He callously and methodically removes danging threads that could interfere with his cementing of his position. He overtly pursues nuclear weaponry, and the technology with which to threaten others with it effectively, to solidify his base myth of "keeping the western wolf at bay". And he intentionally provokes his "enemies" to generate the propaganda with which he can continue to keep his strangle hold on power.
This is why Trump is an idiot. He's not only feeding into it, but is clearly so oblivious to the political machinations, that he is in fact emboldening it. How many times a day do you think Kim's media network plays the "Fire and Fury" quote from a few weeks ago? I would be surprised if that one isn't played at the end of every "news bulletin" or government message for the entirety of Trump's Presidency.
Kim knows he can not win any war they start. But that's not the point of all this. The point is to continue to hold onto power using standard tactics of fear, repression, disinformation and control.
You know, like a despot should.
And Trump is swallowing it all down. Like the ignorant fool he is.