I'm grimly fascinated by North Korea, and read any news or books about that cross my path. I think I understand the exigency for the attack, and it breaks down to two simple things - they do it because they can, and they did it because Kim Jong Il is dying.
The first part is easy to understand - North Korea is not a "rational actor" and is lead by a despot who self-deludes himself with vast displays of martial power that convince him and his cronies that his is the ultimate military power in Asia, and in the world. Kim Jong Il remained in power despite the dreadful famines of the 90's by stressing a "military first" policy in North Korea; convincing the Korean peoples that their survival against implacable and evil outside forces could only be assured by making sacrifices to keep their military power at it's maximum. A disproportionately large number of N. Koreans serve in the military, and it is one of the largest standing armies in the world. Their conventional armaments are more than enough to destroy the S. Korean capital, Seoul, within hours of an outbreak of hostilities, which says nothing about their nuclear arsenal. In addition, sufficient North Korean rivers are dammed near the border that if the dams were destroyed, the flooding could inundate much of South Korea. So, when an amoral and delusional madman commands an army of fanatics within easy striking distance of a modern city full of millions of innocents - playing a game of one-upsmanship is unwise. Ignore it when possible, negotiate and condemn when you can't, and wait for him to die.
The second is more complicated. Kim Jong Il's father, the Great Leader Kim il Sung, created the cult of personality with which he subjugated half the Korean peninsula as a quisling of the Sino-Soviet Communist alliance. Although he was born in Korea, he was raised in exile in China, did not speak Korean, and trained and served in the Russian military during WWII. After the war, his Communist overlords found the actual partisan fighters who had defied Japanese occupation inconvenient and insufficiently biddable, so they were quietly purged. In their place, Kim Il Sung was given credit for all their victories, though his actual contributions were very meager. He was, however, a committed Communist idealogue, and thus fit the bill. With thorough and ruthless efficiency his personal story was changed in the official books to attribute to him any number of quasi-divine powers, and he rapidly created a Communist dictatorship with him as its undisputed Great Leader. The symbolism of him as Great Leader was key to his cult of personality, and to quashing any clamor for reform in North Korea. As both Russia and China went through periods of reform, Kim Il Sung would reject their alliance and remain stubbornly purist in his Communism, creating a uniquely Korean brand of Marxism called "Juche". Juche is based on Korean racial purity, stubborn nationalism and a complete rejection of reform or outside trading. North Korea calls it "self-reliance" but the rest of the world calls it isolationist.
Even before his death, Kim Jong Il was groomed as his successor. If Kim Il Sung was the Great Leader who had liberated Korea from Japan and won a war against the imperialist U.S., forcing the world to kneel and pay tribute (neither of which he did, and in one case never even happened) as well forming the most pure form all governments, Juche Communism - then Kim Jong Il needed some similar rhetorical claim to power. After all, he was born in Russia with a Russian name, and grew up in the wake of his father's success. He had no military victories to call his own, and so needed some claim that would stake him out not just as Korean - but as uniquely and divinely Korean. His official record was amended to say he was born on a holy mountain in Korea, rather than Russia - and he began to accompany his father on tours of advice. Kim Jong Il became known to be the greatest expert in everything - from military matters to industry, agriculture and even film-making. Three years after his father's death, he took power and became "Dear Leader" - the omnicompetent commander who inspired his people to greater industry (though they starved and their economy was essentially bankrupt) and the military to audaciously defeat the aggression of the U.S. and its lackey, the government of South Korea (though no such aggression occurred).
There have been rumors of Kim Jong Il's failing health for years, even suspicion that he was already dead - though this was premature. Probably he suffered from a stroke, but recovered. Now I theorize that his youngest son is being groomed to take his place, and must therefore be granted a quasi-divine super Korean-ness to qualify him to fill the pant-suits of the Great Leader and the Dear Leader. Kim Jong Un is the man in question, and already he is given a sobriquet like his father and grandfather - "The Brilliant Comrade". I predict that when and if North Korea takes credit for the attack, it will be attributed to Jong Un - and the whole situation has been orchestrated to make him a national hero for his tenacious defense against the imperialistic enemies that surround North Korea. That at least, is how North Koreans will see it, and covered in these sorts of laurels, Jong Un may manage to succeed his father despite the resistance of senior Communist party officials who do not want a dynastic rulership in North Korea.
Look for more provocations from North Korea, and the name Kim Jong Un, that's my prediction.