Family and genetics can make you more likely to have a mental disorder, but it’s not guaranteed that if none of your family has a mental disorder then you won’t.
I personally have relatives who have had depression and anxiety and I also have both. On the other hand, one of my closest friends suffers from OCD and none of her family members have any mental illnesses.
It is perfectly possible to have a mental disorder without relatives who have a mental disorder. If you are personally worried you are dealing with mental illness, you should talk to your doctor and see if you can figure out if there isanhtjing going on.
On the other hand, people may just be being rude! Or they think they can diagnose you for whatever reason. Either way, there is no shame in talking to your doctor if you think something is going on, regardless of your family’s health history. Good luck!