Interesting question.
Thinking about this in geopolitical terms, I would separate it into two questions: the "batshit crazy," personality cult-style government and the aggressive foreign policy, which in North Korea's case I would argue is actually quite rational and not crazy at all.
A personality cult-based regime isn't actually that hard to imagine at all. As a couple posters have already noted, there are at least precursors to that in several countries, like Castro, Duvalier, Chavez, etc. Nothing like North Korea, obviously, but the leap of imagination there is not crazy.
The foreign policy part is the issue. Historically North Korea benefits from basically a lucky location. If the Korean peninsula was squarely in China's sphere of influence instead of being divided with the West, the Chinese would have finished off the Kim regime long ago as being far more trouble than it's worth. The same way the U.S. surely would if a Latin American country started threatening to invade all of its neighbours.