In "The Final Battle", the two-part Season 6 finale of Once Upon a Time, there are two outcomes of the Black Fairy's curse:
- Those who stay in Storybrooke (e.g. Emma, Archie) lose their memories of the last few years
- Those who were transported to the Enchanted Forest kept their memories.
The only exceptions to this were the Black Fairy (who created the curse, so presumably kept herself as a loophole), Rumplestiltskin (who secretly used magic to make himself immune to it), and Henry, all of whom stayed in Storybrooke.
But why did Henry keep his memories yet stay in Storybrooke? The Black Fairy seems surprised to find he is "awake" and has his memories, as well as the Once Upon a Time book, which he was not holding at the end of the previous episode. And Rumplestiltskin doesn't indicate that he kept Henry from losing his memories.
So what made Henry immune from the curse? Was it his power as the author?