This did not occur before I started my PhD. It does not occur when I simply say I’m a graduate student. I only say this when people ask what I do as a living (I do not namedrop this).
As others have commented already, it may just be that one meets nasty people every once in a while. However, it could also be a sign that people perceive you as giving yourself airs - e.g. because you [even unconsciously] put an emphasis on the PhD student rather than on your profession.
Side note: Personally, when people ask me what I do for my living, I say "I'm a chemist" (not PhD, nor postdoc - nor did I answer "PhD student"). People around me answer either by "I'm a PhD student at university/institute/in field" or by "profession" or by "profession and currently working on my PhD thesis", and what they answer is quite context dependent: meeting people outside academia, it tends to be "profession".
Assume you meet a carpenter who is journeyman (= holds a qualification to work in that profession).
Consider them answering "I'm journeyman" vs. "I'm carpenter" or even "I'm pursuing my master [craftsman]". At least to me the journeyman answer would sound decidedly weird, and while "I'm working at my master's" sounds less weird in English than in my mother tongue (because we have different words for the crafts master and the academic master) the expected answer would certainly be "carpenter" unless you are in a context where most people are carpenters. You could also say that the expected type of answer is the one that carries most information.
I think the appropriate answer is quite culture-dependent (and culture being even within vs. outside academia).
This tends to occur when I vocalize a strong opinion or disagree with another person’s viewpoint. They might say "not everyone has a PhD like you".
Others have commented already that this may be an ad hominem attack (who you are rather than what your argument is worth) which tells more about the other than about you.
OTOH, it could also be that the others perceive you as trying to gain [unfairly] by putting weight on your being a PhD student and respond to this. (That would be the equivalent error from your side: again who you are rather than what arguments are worth).