re: 我只有一只狗 ;firstly I want to point out that the first 只 would be pronounced with 3rd tone while the 2nd instance (量词 count-word) would be pronounced 1st tone
I don't have official etymology on this but as a native speaker for both mandarin and english I suspect this case is somewhat similar to what's going on with the English "the more the merrier". So, articles (part of speech) like "the" ”a" "an” or the more general/wider classification of determiners (part of speech) like "both" "this" "that", aren't exactly the same as 量词 count words in Chinese but I'd say their functions are very similar. However, what's happening in "the more the merrier" (or other "the x the y", "the less [they know] the better“ or whatever), "the" isn't acting like an article at all, where you expect it to modify or accompany a noun, but it descends from "tha" from middle english rather than from the/article and somewhere along the way "tha" lost other places where it would be used, only retaining the "the x the y" umm linear graph relationship(?if that's the best way to describe what's happening between linking conditions together?), and converged/merged with "the" whose main use is as an article (part of speech). Although, for 只 I don't think it's quite recessed/withered on the "only"(3rd tone) side as much as english "the(tha)", because it's still widely used as "只是" (only/but/however) and is just as common to see it there as seeing it as a 量词 count word.
There are a bunch of other cases of single characters having multiple meanings/pronunciations, plenty of them being "less used case" and others being "specific case/always pronounced one way when used in specific 词"
-- example A, 乐 usually pronounced le4 on its own, means "joy", more fleshed out would be like 欢乐 huan1 le4 ; but if you see it written out in 音乐 "music" it's always pronounced yin1 yue4;; (eg 乐器, musical instrument, yue4qi4) [this is the most drastic example I can come up with off the top of my head, most other alterations in pronunciation/meaning overloaded onto single character are tone diff)
-- example B, 好 usually just means "good" (depending on context might also mean "oh those two are going out", still this pronunciation) most often seen this way and pronounced hao3, but when used in 爱好[ai4hao4] "hobby" or 好奇[hao4qi3] "curiosity" it's always fourth tone hao4