The mathematical meaning of ratio comes from the mathematical meaning of rational, which in turn comes from the mathematical meaning of irrational.
The OED says that we get the word irrational from the Latin word irrationalis, which was used in Latin for both the mathematical and the non-mathematical sense of irrational. It appears that the mathematical senses of both ratio and rational are backformations from irrational.
Euclid called irrational numbers ἄλογος (alogos). Since the word logos in Greek means either word or reason, this would have meant either unsayable numbers or unreasonable numbers. I expect the name originally was intended to mean unsayable numbers; the ancient Greeks used rationals to identify numbers, so an irrational number would have been a number without a name. Furthermore, the word for the mathematical sense of irrational in modern Greek is άρρητος (arretos), which also means unsayable.
Anyway, the word ἄλογος was translated into Latin as irrationalis, and according to the OED, the mathematical sense of irrational is first attested in English in 1551, and the mathematical sense of rational in 1570. The mathematical sense of ratio is first attested in English in 1660, so it seems that the mathematical meaning of ratio was a backformation from rational. The word ratio means both reason and calculation in Latin, but I haven't found any evidence it was used to mean ratio, i.e., one quantity divided by another. One of the meanings of the related adjective rata, as in pro rata, does seem to have been in ratio, so the choice of ratio to mean this was not too unreasonable.
The backformation from rational to ratio presumably happened in English, because the French word ratio (same meaning as in English) was borrowed from English and not Latin (see this link to le trésor de la langue française informatisé).
The backformation from irrationalis to rationalis happened in Latin.