Many series that I have seen have "x in Wonderland" episodes where they have retellings/variations of Alice in Wonderland with the characters from the show. Examples of this include Ouran High School Host Club (episode 13), Black Butler (season 2 OVA 1 and 4), Cardcaptor Sakura (episode 55), and Code Geass (OVA). What is the origin of this? Is there some sort of cultural basis for this?
I guess this is because of it's overall popularity. According here,
Alices Adventures In Wonderland is a pretty well-known work: it can be associated with world-crossing fantasy, drug imagery, lolita fashion and other aspects of Victorian England, political satire, and who knows what else. No wonder it shows up a lot in anime, shock horror (it's a frequent target of Grimmification, usually with lots of blood), and emo teen novels. (You know the kind — usually involving vampires, eating disorders, or vampires with eating disorders.)
This is interesting because I see many answers saying it's not limited to anime, but from what I've seen, it's not limited to Alice in Wonderland.
While it seems to be the most popular one by far, I also have seen re-editions of the Japanese fairy tale 'Momotaru, the Peach Boy', examples include: Assassination Classroom, Maid-Sama and Free!!! (All of which are amazing and I would recommend watching from the bottom of my heart.)
I agree that they are many for the purpose of buying time for the animators to work on bigger pieces such as finales, they also are comic relief episodes that put loveable characters in familiar situations.