An interpretation that allows weapons to belong to either set depending on use, encompasses both the sentence and the table.
However, if you use only the bolded text to determine what type of weapon is being used, then any ranged weapon used within 5 feet of an enemy necessarily becomes a melee weapon, despite still being used to make a ranged weapon attack. Unless firing an arrow from a bow at an enemy within 5 feet of you counts as a melee weapon attack (hence ignoring your disadvantage for making a ranged weapon attack while a hostile creature is within 5 feet of you), because it would become a melee weapon based on the circumstances.
Be warned: long post ahead taking every piece of relevant information (that I can find, I may have missed something) about weapon attacks and throwing them into the "specific beats general" mindset.
[SBLOCK]Let's find the definition of weapons, then put it into the basis of "specific beats general". At the beginning of the
Weapons category, it's stated that every weapon is either a
melee weapon or
ranged weapon. It is also stated that
melee weapons are used to attack a target within 5 feet of you, while a
ranged weapon is used to attack a target at a distance.
Right here we have two general rules about weapons. Barring any specific cases, these two facts must be true:
1. Every weapon is classified as either a
melee weapon or a
ranged weapon.
2. Every
melee weapon is used to attack a target within 5 feet of you, while every
ranged weapon is used to attack a target at a distance.
In the "Weapon Proficiency" section, no text provides further clarification; the above two points still stand. However, we get to the "Weapon Properties" section and a few specific rules show up which contradict the second of the previous statements:
3. If you use a weapon that has the
ammunition property to make a
melee attack, you treat the weapon as an improvised weapon; that is, it deals 1d4 damage and requires a separate proficiency.
4. A weapon with the
reach property adds 5 feet to your reach when you attack with it; that is, a
melee weapon with
reach can be used to attack a creature within 10 feet instead of 5.
5. If a weapon has the
thrown property, you can throw the weapon to make a ranged attack. If the weapon is a
melee weapon, you use the same ability modifier for that attack roll and damage roll that you would for a
melee attack with the weapon.
Point 5 brings up a question as to the inherent differences between a melee attack and a ranged attack: we must now find general rules that state these differences so that we can understand
what, exactly, this specific rule beats. In Chapter 7: Using Ability Scores, we find:
6. You add your Strength modifier to your attack roll and damage roll when attacking with a
melee weapon such as a mace, a battleaxe, or a javelin. You use
melee weapons to make
melee attacks in hand-to-hand combat, and some of them can be thrown to make a
ranged attack.
7. You add your Dexterity modifier to your attack roll and your damage roll when attacking with a
ranged weapon, such as a sling or a longbow. You can also add your Dexterity modifier to your attack roll and damage roll when attacking with a
melee weapon that has the
finesse property, such as a dagger or rapier.
We can see that the book distinguishes between
melee weapons and
melee weapon attacks, as well as
ranged weapons and
ranged weapon attacks. Although
ranged weapons are primarily used to make
ranged weapon attacks and
melee weapons are primarily used to make
melee weapon attacks, there are some cases where
ranged weapons are used to make
melee weapon attacks and some where
melee weapons are used to make
ranged weapon attacks. We can also see a fourth specific rule from point 7: weapons with the
finesse property can use Dexterity as their ability modifier for
melee attacks.
General rule 1: Every weapon is classified as either a
melee weapon or a
ranged weapon.
General rule 2: Every
melee weapon is used to attack a target within 5 feet of you, while every
ranged weapon is used to attack a target at a distance.
General rule 3: You add your Strength modifier to your attack roll and damage roll when attacking with a
melee weapon such as a mace, a battleaxe, or a javelin. You use
melee weapons to make
melee attacks in hand-to-hand combat, and some of them can be thrown to make a
ranged attack.
General rule 4: You add your Dexterity modifier to your attack roll and your damage roll when attacking with a
ranged weapon, such as a sling or a longbow. You can also add your Dexterity modifier to your attack roll and damage roll when attacking with a
melee weapon that has the
finesse property, such as a dagger or rapier.
Specific rule 1: If you use a weapon that has the
ammunition property to make a
melee attack, you treat the weapon as an improvised weapon; that is, it deals 1d4 damage and requires a separate proficiency.
Specific rule 2: A weapon with the
reach property adds 5 feet to your reach when you attack with it; that is, a
melee weapon with
reach can be used to attack a creature within 10 feet instead of 5.
Specific rule 3: If a weapon has the
thrown property, you can throw the weapon to make a ranged attack. If the weapon is a
melee weapon, you use the same ability modifier for that attack roll and damage roll that you would for a
melee attack with the weapon.
Specific rule 4: When making an attack with the
finesse property, you use your choice of Strength or Dexterity for your attack and damage rolls. You must use the same modifier for both rolls.
Ramifications of Specific rule 1: This means that General rule 2 must not necessarily be true, because a
ranged weapon can be used to attack a target within 5 feet of you, making a
melee attack.
Ramifications of Specific rule 2: This also means the part of General rule 2 regarding
melee weapons is not necessarily true, because not every
melee weapon must be used to attack a target within 5 feet of you.
Ramifications of Specific rule 3: This, in conjunction with Specific rules 1 and 2, makes General rule 2 entirely obsolete; some
melee weapons can be used to make a
ranged attack against targets not necessarily within 5 feet of you.
Ramifications of Specific rule 4: With General rule 4 making an allowance for the
finesse property, this rule simply stops General rule 3 from encompassing
all melee weapons.
The table of weapons acts as a specific rule, and is the only place where the assumptions of General rule 1 might be challenged. However, lacking any specific instances where a weapon is considered both a
melee weapon and a
ranged weapon, we are forced to conclude that General rule 1 is true in all cases: every weapon is either a
melee weapon or a
ranged weapon, regardless of whether it's currently being used to make a
melee weapon attack or a
ranged weapon attack.
Thus, we have the following rules regarding weapons and weapon attacks:
1. Every weapon is either a
melee weapon or a
ranged weapon.
2. You add your Strength modifier to your attack roll and damage roll when attacking with a
melee weapon, whether the attack is a
melee attack or
ranged attack. If a weapon has the
finesse property, you use your choice of Strength or Dexterity for its attack and damage rolls.
3. You add your Dexterity modifier to your attack and damage roll when attacking with a
ranged weapon, whether the attack is a
ranged attack or a
melee attack. If a weapon has the
finesse property, you use your choice of Strength or Dexterity for its attack and damage rolls.
4. A
ranged weapon with the
ammunition property used to make a
melee attack is considered an improvised weapon, and uses the rules described therein.
[/SBLOCK]
Phew, glad that's done with. I'm afraid that no weapon can belong to the subsets of both a
melee weapon and a
ranged weapon; the rules are extremely clear on that. The reason the bolded text you called out is there is to give a(n extremely) rough guideline as to what ranged and melee weapons are before going into further detail later on in the book.