IME, it's all "in the eye of the beholder," meaning people see other people through their own, very personal lense. All their cultural life experiences are instantly brought to the front with little to no filter. They base there assumption of your race/ethnicity/nationality/sexuality etc on what they can identify from what they have seen before and how it matches you in *this instant*.
I'll give you an example I have lived with my entire life:
My mother was Mexican and my father Irish, but my mother didn't look like the stereotypical Mexican that all NY's think of when they think of a Mexican.
So I'm born with fairly light skin (my brother is even lighter) and green eyes. I'm over 6 feet tall. So nobody thinks I'm Mexican. But most people naturally *assume* I'm Spanish, and based on my physical appearance and since I live in NY I must be Puerto Rican or Dominican
Stereotypes may not be pleasant, but I don't think they are always used in a strictly negative way. I mean, there is a lot of information to be processed in a day, so I think there is a tendency to group things into categories for easier absorption.
And I don't get too miffed when someone thinks I'm Puerto Rican, I actually kinda like the shocked look I get and the "you're Mexican?!" question that invariably follows.