Korean has no /f/ sound (unvoiced labiodental fricative), so it has to approximate it with a sound it does have. There are two possibilities.
ㅍ is a labial plosive that is heavily aspirated. The heavy aspiration makes it similar to a fricative, so it sounds similar. It's also unvoiced, so that helps. So it's used in loanwords like 파일 (file).
ㅎ is generally an 'h' sound, but its pronunciation actually changes a lot depending on the vowel that follows it. So when it's followed by an ㅜ (or ㅗ, to a lesser extent) it makes a bilabial fricative sound - quite similar to the labiodental fricative sound of the English 'f'. So the ㅎ makes a good substitute for the English 'f', at least when we can put an ㅗ or ㅜ after it, like muffler -> 마후라 and fry[ing] pan -> 후라이팬, where we have to insert a vowel anyways.
This is found in Japanese too, where ふ, though belonging to the 'h' set, makes a [ɸu] sound - and is written fu in English. Words borrowed through Japanese will especially tend to use 후 to translate the English 'f' sound.
Incidentally, we can see ㅎ used to translate other sounds in European languages - [Van] Gogh is translated 고흐, because 흐 makes a velar fricative sound, and Zurich is translated 취리히, because 히 makes a palatal fricative sound.