Clearly sanctions only restrict specific industries, so N. Korea does also gain funds through international commerce that isn't sanctioned. Also, each nation is capable of having a completely internal economy, and industry that is devoted to purely national progress.
Clearly some combination of these funding sources has been applied to the interest in nuclear weapons.