So, the f->v shift can be traced back to Old English, where v wasn't its own letter, but merely an allophone of f. The /v/ pronunciation was used when it was placed between vowels or voiced consonants, and the /f/ pronunciation was used otherwise.
So the declination from wīf to wīfes meant that the actual pronunciation of the f went from /f/ to /v/ (much like today today), because it became positioned between two voiced vowels (I should point out, in OE wīfes was a two-syllable word [wiːvɛs]).
Now, over time, a few things happened:
- V became its own phoneme and began to be represented in the orthography of English
- English became less inflected
- We stopped pronouncing the last syllable
So we have a couple competing forces:
With the v sound now entrenched in the spelling of many words, the idea of the f->ves for pluralization became a "rule" and was carried on and used by analogy when forming related/similar words.
However, with the lack of a vowel sound in the final syllable, there was no longer a need to force the voicing of the labial fricative, leaving us with two viable pronunciations/spellings: the unvoiced pair [fs] (-fs) or the voiced pair [vz] (-ves)
Now, I can't find a good source for determining which word used which one, so treat the following as my own supposition:
My expectation then is that when a particular word entered the lexicon would greatly influence which option is chosen. Words entering in Old and Middle English (and words derived from or related to them) would be much more likely to use the -ves option, while words entering later, particularly if they enter as loanwords from a Romance language, etc. would prefer the more regular -fs.
Additionally, now that there's no phonetic requirement to voice the consonant, we're seeing linguistic regularization kicking in, slowly pushing the -ves pluralization out in favor of the more regular -fs option. So forms like rooves / hooves start to give way to roofs / hoofs and depending on where they are in that process, you see that one form may be preferred over another, or they may both be equally viable.