Scott Horton gives a very brief history of what happened (57m38s):
It was all George [W.] Bush's fault. [He] probably deliberately provoked them into doing that.
First, [the US] abnegated the Agreed Framework deal, then they announced a whole new round of sanctions, then they announced the Proliferation Security Initiative which said that we can seize all your boats on the high seas and do whatever we want with them [...] and then they announced the Nuclear Posture Review that said we just might attack you with nuclear weapons.
And only then did the North Koreans withdraw from their end of the Agreed Framework, announce they were withdrawing from the Non-Proliferation Treaty like in the deal it says you have to announce 6 months beforehand, and only then did they withdraw from the treaty, kick the IAEA out and start making nukes.
And i guess the thinking [in DC] - if you can call it thinking - was, don't worry, we'll be done in Baghdad and we’ll be ready to go to Pyongyang before they get their first nuke together, except that Oops instead we just essentially handed them an arsenal of nuclear weapons when they were perfectly happy within the Non-Proliferation Treaty as a threshold state under the Agreed Framework deal which America had never even lived up to our side of.
It just took Bush repudiating it and threatening them with an H-bomb first strike to make them withdraw from their end.