It is a contamination of the now lost dual number from back when Old Russian used to have a three-number system: singular, dual, and plural.
For history of Russian grammar I highly recommend Киржаева, В. П. Историческая грамматика русского языка. (Киржаева В. П. Историческая грамматика русского языка //Саранск: Изд-во Мордов. ун-та. – 2010.)
Here's the actual quote:
Иначе процесс утраты дв.числа происходит в формах Им.-Вин.
Если сравнивать формы дв.ч. с формами Им.мн. и Р.ед., то окажется, что у существительных мужского рода эти формы совпадали с Р.ед. Примерно с XV века исконная форма дв.ч. существительного в сочетании дъва стола уже воспринимается как сочетание числительного с существительным в Р.ед. По аналогии с именами мужского рода такое переосмысление получают и слова женского и среднего родов в сочетании с числительными две/два, обе/оба: две руки, два поля.
Формы Р.ед. вытеснили и формы Им.-Вин.мн. при числительных 3, 4: то есть вместо ожидаемых форм 3 городи, 4 рубли — 3 города, 4 рубля.
Таким образом происходит не только утрата форм двойственного числа, но утрата самой категории двойственности.
Утрата двойственного числа в живой речи происходит уже в XI веке. Однако использование всех изменяемых частей речи в двойственном числе сохраняется как норма в книжно-славянской письменности вплоть до XVII века.
Here's my translation:
The loss of dual number took a different path for nominal-accusative forms.
Comparing dual forms to plural nominal and singular genitive, it turns out that for masculine nouns, these forms match singular genitive. From approximately XV century, the original dual form of the noun in the phrase дъва стола ("two tables") is already interpreted as a combination of a numeral and a singular genitive of a noun. Feminine and neuter words receive the same reinterpretation as masculine words, when used with numerals две/два ("two"), обе/оба ("both"): две руки ("two arms"), два поля ("two fields").
Singular genitive forms have also forced out plural nominal-accusative forms following numerals 3, 4: so instead of the expected form 3 городи ("three towns"), 4 рубли ("four rubles") — 3 города ("three towns"), 4 рубля ("four rubles").
Thus, not only the form of the dual number was lost, but the dual category itself.
The loss of dual number in speech occurs in the XI century already. However, the use of all inflectable parts of speech remains a norm in written Slavonic up until the XVII century.
To put it simply: there is no rule. It is just a vestige of the way the language used to be way back when.