Cap'n Kobold
Hero
Part of the reason that this issue appears in martial/caster debates is alluded to in your second paragraph: rather than selecting some ranged attacks from the dozens of class features available, the fighter must be built from the start to specialise in them.
This also gets into the discrepancy between Dex and Str: Outside of a few distinct builds using specific feats, a fighter using Dex is just as good in melee as one using Str, but also has better skills, and most importantly - initiative and ranged attacks.
Thus the issue is not just that the ranged attacker gets to fight well in situations that the melee-focused one doesn't. It is that they're not really giving anything up to do so.
Outside of simple effectiveness concerns, Str-based martial melee characters will often have a place due to concept however: They're iconic. Mixing it up in melee might not be as optimal as playing a ranged attacker or caster of a flying race, but it is something that many people simply would like to play.
This also gets into the discrepancy between Dex and Str: Outside of a few distinct builds using specific feats, a fighter using Dex is just as good in melee as one using Str, but also has better skills, and most importantly - initiative and ranged attacks.
Thus the issue is not just that the ranged attacker gets to fight well in situations that the melee-focused one doesn't. It is that they're not really giving anything up to do so.
Outside of simple effectiveness concerns, Str-based martial melee characters will often have a place due to concept however: They're iconic. Mixing it up in melee might not be as optimal as playing a ranged attacker or caster of a flying race, but it is something that many people simply would like to play.