Here there's some other people asked the same question. 忆珩 and Nimmer provided answers that maybe very helpful to your question:
In Middle Chinese, 二's initial was ȵ. During the time when the northern China was ruled by Jin Dynasty and southern China was ruled by Song Dynasty, the separation makes the northern and southern Chinese language evolves on different path.
In Mandarin, ȵ first became ʐ and then further shifted to zero consonant. Notice that characters with initial ȵ are pronounces as nj-. The medial is j/i. Though ȵ disappeared eventually, the medial persists in various forms. Eventually, this medial becomes ə and then becomes an erhua ɚ.
In various southern Chinese languages, each of them evolves in their unique path. But due to the official status of Mandarin, southern Chinese are greatly influenced by the phonetical change is Mandarin. So roughly speaking, we quite often can observe that some southern Chinese maintains certain characteristics of Middle Chinese. That's why 二 still maintain the original initial ȵ, or it's variant n in some regions. (But notice that sometimes character with initial ȵ in Middle Chinese could have other initial such as ʐ or ə in southern Chinese.)
As for Japanese on'yomi pronunciation, a great majority of them still maintains the origin pronunciation at the time the kanji was adopted into Japanese. That's why on'yomi shares many characteristics as Middle Chinese.