If you get caught and can’t pretend to be stretching or scratching your head, you can always say:
“Oops! My bad. I thought you were somebody else.”
Similarly, sometimes we cannot tell if someone is male or female based on how they look.
We might mistake them for the other gender. Conversely, someone might mistake us for the other gender.
If you are unsure when you meet someone, and the person’s name doesn’t make this clear, you can always ask: “What gender pronoun do you prefer?” Or when you introduce yourself, you can say, “My name is Sam. I prefer to go by ‘they/them'”
If we make a mistake, or if someone makes a mistake with us, we might feel flustered. If you can, try to roll with it or laugh it off.
Here is a link to a podcast about this situation. Listen to how this person handles it.