Necessity is the mother of invention but the fact of the matter is that North Korea has a GDP of $20 billion while South Korea it's 1.6 trillion. North has limited resources and capital. In the 80's, Iran began purchasing a variety of weapons from North Korea, including tanks and missiles.
if you think about it, purchasing weapons from a producer is almost like a form of investment. Future projects however require upfront investments before the weapons are even ready. Investments can be made in the form of cash, resources (oil), material (vital metals) and research contribution. Once one side invests enough resources, capital, research, eventually it becomes a joint project.
I'm pretty certain that Iran has the blueprints and know how when it comes to building an ICBM and nuclear arsenal. For political reasons, Iran keeps its range limited to 2000 KM but the Khorramshahr missile for example is a variant of the Hwasong-10, which has a range of 3000-4000 KM.
If such an arrangement exists, then it's perfect for both Iran and North Korea as every single launch and every single bit of research conducted benefits both sides. This would be a perfect explanation as to how and why, since the 80's, despite harsher sanctions, North Korea has been able achieve so much, despite all the odds.
This is the problem with the west and its approach to North Korea. Always under estimate and then get shock after shock as NK hits milestones which the west thinks it cannot ever hit. I remember the days when they used to say NK would never have a ICBM, how did that turn out? They have Hwasong-15 and even a Hwasong-16 now both which can deliver 1-ton nuke to anywhere on the surface of the earth.
I dont doubt North Korea is a developing country but it is not as dirt poor as the west makes it out to be if it can develop so many different weapons systems in the span of a single decade. I think North Korea will continue to shock the west for many years to come.