Jefferson (aka the Mad Hatter) is a person who with his hat trick travels a lot, hears a lot and thus knows a lot. In one of the major stories on his part is when he try to help Regina by bringing The Doctor (Frankenstein) to her in hopes of reviving her love (Daniel the stable boy), showing the range of Jefferson's knowledge.
AFAIK there is still no direct explanation on how Jefferson was brought to Sorybrooke. As he is one of the few who remember the old life he is a special case. By all accounts it seems like Regina brought him with her when she cast the spell. Now how she did that is not explained directly, but it could be that she was able to trough the power of the dark spell, or by some knowledge that Jefferson had.
Regina is staring at her apple tree from the window of her office,
when Jefferson enters.
Regina : Jefferson. So, you got my message.
Jefferson: How could I miss it? You know I watch her.
Regina : It must be so painful, your daughter Paige being oh, so near.
Jefferson: Grace. Her name is Grace. You should know that – you
changed it. What do you want?
Regina : Your help.
Jefferson: And what makes you think, I won’t kill you after everything
Regina : Because you don’t have it in you. If you did, you would have
done it twenty-eight years ago when I brought you here. Because you
know if I’m dead, you’ll never get back to your daughter. And I have a
way for us to both get what we want.
Regina retrieves Jefferson’s hat box and places it on the table.
Jefferson: My hat.
Regina : I want you to use it again.
Jefferson: I can’t make it work. No one can. Not here. Not without
Regina : Well, then you’re in luck, because I happen to have some. Not
a lot… But hopefully, enough… For one last journey.
So as per Regina: she brought him there. (He did not go there on his own, was brought by someone else etc.)
All the lands or some of the lands
Whilst Wonderland was not affected by the spell like for example the Enchanted Forest, it is mentioned in the original script for the pilot that all lands would be touched:
Charming shoots her a look as Rumple leans up as close to the bars as
he can get. Presses his face between the narrow slit. Bares his
blackened, jagged teeth as he speaks
The queen has created a powerful curse. And it’s coming. It won’t
just affect this land. It will touch all the lands… Soon there
will be no more magic. Soon you’ll all be in a prison. Just like me.
Only worse. Your prison -- all of our prisons -- will be time.
He speaks nonsense.
If only it were nonsense. Time will stop and we will all be trapped.
Suffering for eternity as the Queen celebrates. Victorious at last.
(beat; sinister) No more happy endings.
In the final cut the dialogue is changed to:
The Queen has created a powerful curse. And it’s
coming. Soon, you’ll all be in a prison. Just like me, only worse.
Your prison, all of our prisons, will be time. Time will stop, and we
will be trapped. Someplace horrible, where everything we hold dear,
everything we love, will be ripped from us while we suffer for all
eternity. While the Queen celebrates, victorious at last. No more
My reason for mentioning this is that it is possible Wonderland was somewhat affected making it possible for Regina to extract Jefferson from the land.
From The Enchanted Forest
As Cora (the Queen of Hearts / Miller's Daughter) was in the Enchanted Forest when the Dark Spell was cast, and protected herself and Hook in the corner of the land, it is possible that she and Jefferson by some means escaped Wonderland together, or that he managed to do it alone shortly before the spell. As such he would have been brought to Storbybrooke with all the others, but also given a special treatment by not forgetting. This can also be a result of his madness.