I don't think it works for everyone, and I don't know how effective it is for other people who are with you, but here's my all-powerful technique for things like that.
Be a daze.
Pretend not to notice. Act like it's not about you. Pretend not to understand. Always assume the best, to the extreme. If the laughing people address you, go "eh? uhm, yes? what?" naively, and only after pretending not to hear it until it becomes obvious you must have heard it.
If you manage to do that, you'll be hurt much less. For one, eventually, always acting like you don't notice, you might as well start noticing it less for real. Also, if it doesn't look like it affects you, people you are with should feel better. And finally, most bullies eventually get tired of throwing knives only to have them go through a ghost who doesn't even seem to hear the insults.
There's always a dilemma about the attitude to have when going out as a girl and not passing very well. Be too "low-profile" and you'll seem unsure of yourself, which will cause people to doubt you further, as well as attract the cruel type of bully, who enjoys sinking people who are low even lower. Be too "proud" and you'll overly attract attention, and people will look at you more, wondering more. And those bullies who feel must defend themselves or the planet from perceived threats (mostly illegitimate threats but anyway) will feel you're on the offensive and will attack.
I think the daze attitude is pretty useful, because it removes this dilemma. You're not being low and miserable, or high or confronting. You're just elsewhere, out of all that, and as long as your acting isn't so bad that you seem to be ignoring them (making them angrier), you're good.
In my 22 years of being bullied by tons of people, from family to classmates to strangers, all of which ended up giving up, I can certify that the naive daze technique has a wonderful potential. Now, many (most?) people have a strong urge to fight back when attacked, and for them, it might not be possible.
As for preventing these occurrences, I guess the only thing that can be done is to work on the passing. You can get people used to you or tired of laughing at you, but new people always have a potential to laugh at others at first.
There's also, perhaps, the choice of appearance, until you pass better. Someone who doesn't pass well and dresses all girly in a dress, make-up and jewelry might be laughed at for being an obvious "man in a dress", whilst the same person dressed in girls'-but-sort-of-andro clothes might just be regarded as a "geek" girl who doesn't care much about her looks, or someone on a busy day, or their gender might be confusing.
If people feel you're "attacking" the concept of gender by being bold, they are very prone to attacking you. But if you're keeping a lower profile, then to them, it'll feel much more an aggression than a "counter-attack" to attack you, and a huge proportion of people who might have laughed at you in the first case won't in this one. Besides, if people are confused, wondering about your gender, they might look at you funny, but they will be too busy asking themselves questions to attack you.