Here there's some other people asked the same question. 忆珩 and Nimmer provided answers that maybe very helpful to your question:
忆珩:
二、耳等字属于日母止摄三等,日母古音是个舌面的鼻音ȵ,本来是从泥母n中分化出来的,后来北方方言中日母鼻音消失并且卷舌化成了ʐ,其中止摄三等字变成了零声母的er。而在南方吴语、闽语等方言里日母又归回了泥母n,就是现在这种状况了。简单的说大致就是这么个历史过程。
至于说历史因素,应该是宋金对峙导致的南北方言分离(这使得现在北方方言的几大特征都是在元朝开始显著起来),地理因素自然就是长江了吧。
Nimmer:
要了解这个问题必须有一些汉语音韵学的背景了。”二“是日母止摄三等,上古的声母应该是n。到了中古时期以前的发音应该是ȵi。”ȵ“是一个跟n接近的鼻音。对于日语中古的读音,各家有分歧。应该不是”ȵ“,就是”ȵʑ“。在北方,这个鼻音发生了擦音化,在元代变成了ʐʅ。之后成了现代的ɚ
在北方话的发展过程应该是这样的:ȵi>ȵʑi>ʑi>ʐɨ>ʐʅ>ɻʅ>əɻ>ɚ
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.