I think that transformation only exists when the /h/ or /f/ is the first letter.
This transformation is related (in theory) to the pre-Romance languages; this case is attributed to euskara substrat that also influences de aspirated /h/ in the Gascon language.
Sources:
Historia del español
Where we found: la desaparición de f- inicial en muchas palabras que en latín llevaban este sonido, y, supuestamente, el llamado betacismo, debidos, probablemente, a la influencia del vascuence o del íbero (nótese que la aspiración de /h/ también se da en idioma gascón que habría tenido igualmente un substrato vasco).
The disappearance of initial f in many words that in Latin have this sound, and, presumably, the so-called betacism, is probably caused by the influence of Basque or Iberian (note that the aspiration of /h/ is also found in the Gascon dialect that would have had the same Basque substrate).
Lenguas romances
WHere we found: Igualmente algunos estudiosos consideran que un idioma que sirvió de sustrato para las lenguas ibero-romanas fue el vasco, que posiblemente aportó al cambio /f/ al /h/ al inicio de las palabras en español (el latín farina se convirtió en “harina”), y palabras como “izquierda” (vasco ezkerra).
Some scholars believe that one language that served as a substrate for Ibero-Romance language was Basque, which possibly contributed to the change from /f/ to /h/ at the beginning of words in Spanish (Latin farina became "harina"), and words like "izquierda" (Basque ezkerra).