The accepted reply (which seems to have been accepted solely because it was the only reply) does not answer the question.
Maybe an answer can be inferred, if the reader happens to be a lawyer, and happens to be intimately familiar with the actual decision and reasoning in Torres v. Puerto Rico from 1979, but the answer sure doesn't leap to the eye.
It seems to me that the real answer is this:
a. The U.S. constitution is based upon the principle that no action is against the law, unless the Constitution or some Federal or State statute prohibits it.
b. A state (so, clearly, not Puerto Rico) passed a law that prohibited same-sex marriage, probably long ago. The Supreme Court decided that the state law in question was now unconstitutional, on the basis that it violated the 14th Amendment to the constitution (maybe this was a law that long pre-dated that amendment). The court was saying simply this: that such a prohibition is void everywhere for breaching the Constitution.
c. For the reason mentioned in the previous answer, decisions by the Supreme Court have immediate effect. Thus the court's decision took effect, in 1979, throughout all the territory in which the Constitution applies (regardless of whether or not that place is a State: for example, Washington DC is not a state, but I doubt anyone would seriously argue that the Constitution does not apply there).
d. It is clear from all the circumstances that some people resident in Puerto Rico are citizens of the United States (since on occasion they have objected to their not being allowed to vote in US Presidential elections), but that some are not.
e. The 14th amendment does not talk about states, it talks about citizens. It says that "no State shall make or enforce any law which shall abridge the privileges or immunities of citizens of the United States", which means only that it is contrary to the Constitution to make (or enforce) such a law.
f. On its plain language, it does not bar Puerto Rico itself from making such a law, because it doesn't need to. Puerto Rico cannot make a law of that type, not being a sovereign state. For example, it cannot make a law of a type which only a sovereign body, i.e. the US Congress (or e.g. the Government of Canada), could make -- in other words, it cannot make a Federal law.
g. Further, there is no need, either, to bar Puerto Rico from making those laws which, not being even a State of the Union, it lacks the authority to make. In effect, it is being treated in the same way as (say) Arizona or Colorado were treated in the 19th Century, when they too were only Territories, not then having become States. Unless and until it becomes one, it lacks even the legislative power of a State.
So it makes the situation more comprehensible to look at it on an unusual basis: that which many regions of North America formerly had, before becoming States in their own right. Lacking legislative capacity, they nevertheless adhered to the Constitution.
Residents of the Territory of Arizona, for instance, could not vote for the President, because as a Territory it had no votes in the Electoral College. This is also why residents in Puerto Rico have no vote in those Elections, even if they are US citizens by birth, since there is a residential qualification too, but they are not resident in a State.
h. But the 14th amendment does talk about citizens, and they are not defined by whether they are resident in a State. It says clearly that States may not "abridge the privileges or immunities of citizens of the United States", thereby granting the right of equal treatment under the law to US citizens (wherever resident).