Many of the fairy tales collected by the Grimm's have a moral. Is a moral lesson a requirement for fairy tales?
Some fairy tales don't have morals, and lots that do have morals that aren't that useful.
For instance, the Grimm brothers wrote many amoral stories, and many (not just the Grimm's) are believed to be jabs at the government or royalty at the time.
Snow White is based on Margarete von Waldeck, a girl with a horrible relationship with her stepmother, from Germany in a town where children ("dwarves") were exploited in the coal mines.
Cinderella is based on Rhodopis, and the story of Cinderella goes back well before the fairy tale. Rhodopis was a slave, Charaxus fell in love with her, and bought her freedom. He received an angry poem from his sister.
Dick Whittington and His Cat is based on Richard Whittington who became a successful textile trader, who had a cat. See this image.
Hansel and Gretel could be based on the famine of 1315-1317, or it could be based on the story of Katharina Schraderin, a baker who in the 1600s, made a ginger bread cookie so nice that a jealous male baker accused her of being a witch. She was driven from town but angry neighbors brought her back to her home, and burned her to death in her own oven.
The Pied Piper of Hamelin could actually be a true story in itself. The story is set in 1284. The town of Hamelin actually exists, and there are records of 1300 AD of a stained glass window in the church showing a piper leading children out the village. At the time, stained glass windows were a way of showing current events and remembering them. There is also a manuscript from 1440/50 AD that says that in 1284, in the town of Hamelin, 130 children were taken away by a piper and never heard of again. Although there are no rats mentioned, there could have been a rat infestation at the time, and the stories could have been merged. As for why the children were taking away, there are several theories. The rats could represent a plague that killed the children, the piper could have been a paedophile or murderer that took the children, or maybe just a child trafficker.
These examples show that fairy tales weren't written to have a moral that children could learn, but storied of real life events.
* - These are suspicions that haven't and cannot be proved
There's a terminology conflict here. A fairy tale is a fantastical adventure, set in an indistinguishable far-off place and time, in which a good character goes through hardship and comes out with a good/happy ending.
I think most fairy tales have a moral, when it really comes down to it, but it is not a requirement. Mostly, fables (such as those of Aesop) are the ones that require morals at the end.