Genderbending has a surprisingly long and varied history in folklore. It involves both crossdressing and sex changes. It can be temporary or permanent as well as comedic or serious. Characters who indulge the practice range from gods to mortals and their morality - or lack thereof - is equally varied. While it would be impossible to give a comprehensive list of examples, the following should serve as a decent starting point.
Crossdressing Women:
Agnodice
This legend comes from Hyginus’s Fabulae. It says that women were dying from health complications because 1) there were no female physicians and 2) the women did not trust the male doctors they had. A girl who wanted to learn medicine disguised herself as a man, tutored under Herophilus, and served treated the women of Athens. But when the men stopped receiving medical calls from women, they became jealous. Agnodice was accused of seducing the women - who were faking illness - and even revealing her sex didn't help her. Then the women of Athens chastised the men for condemning the only doctor who helped them and they decided to let freeborn women learn medicine.
Mulan
A Chinese legend from the Yuefu Shiji. It tells of a girl who chooses to take her father's place in the army during the war. She goes all over town buying supplies (horses, weapons, etc.) and rides out without telling her parents. After serving for a decade, she returns home. When her old comrades visit they're shocked; they had no idea that she was a woman and Mulan explains that, essentially, males and females are more alike than not.
Transwomen (Male to Female):
A Hymn to Inanna (lines 115-131)
An ancient Sumerian poem by Enheduanna. One line says that "To turn a man into a woman and a woman into a man are yours, Inana."
Bhangaswana
A myth from the Mahabharata. A king wants children but struggles to conceive. During a ritual meant to aid the baby making process, he offends the god Indra, who leads him to a magical lake that turns him into a woman. However, she resigns herself to her fate. Ceding the kingdom to her sons, she moves into the forest where she meets an ascetic and becomes his wife. They have one hundred sons whom Indra causes to battle to the death w)ith the other princes. After a conversation between the mortal woman and the god, where she apologizes for her mistakes (and claims a mother loves her children more than the father), Indra decides to revive all the boys. He also offers to change her back into a man. She declines on the ground that female orgasms are better.
Story of the Abbot of Druimenaig, Who Was Changed into a Woman (pages 176 - 178
A legend found in various medieval manuscripts (e.g., Book of Fermoy). According to the story, a man finishes preparing an Easter banquet and decides to visit the hills. He falls asleep, reawakens, and learns that he's been transformed into a. he struck them again. Initially, disbelieving, she meets a random woman who confirms the truth. After a short journey, she meets and marries an erenagh, with whom she had seven children. She revisits the hill that transformed her and is returned to her male state. He then goes about explaining the situation to his old and new family and his ex-husband decides to share take half the children while he takes the other half (the last one goes to fosterage).
Crossdressing Men:
Achilles
A segment from the Statius' fragmentary Achilleid. Achilles is taken to an island by his mother Thetis to keep him safe from conscription. She tries to convince him to wear women's clothes but he refuses. Then a bunch of pretty girls arrive and Achilles is so smitten with one that he agrees to his mother's plan so that he can get closer to her. It works. They even have a son together (via rape). But Achilles is exposed by two soldiers who then recruit him for the war.
Þrymskviða
A story found in the Poetic Edda. It recounts how Thor woke up one morning and found his hammer missing. He confided in Loki who helped him locate it. The impish deity told him that a troll had stolen it but would not return it until Freyja, goddess of love and fertility, agreed to marry him. She refused. The gods convened and decided on a plan: disguise Thor and Loki as Freyja and a bridesmaid, and have them go to the tolls. Thor reluctantly agreed. He behaved unladylike at the banquet (eating too much, glaring at the bridegroom, etc.), which Loki made excuses for until the hammer was returned. Thor proceeded to kill everyone.
Transmen (Female to Male):
King Sikhidhwaja the Hermit; Chudala as the Brahmin Boy Kumbha
A narrative arc in the Yogavasishtha. King Sikhidhwaja rejects his wife's wisdom and forsakes his kingdom to live in the woods. Chudala decides to use her powers - including astral projection and shapeshifting into a man - in order to help her husband learn valuable lessons. After a series of philosophical discussions, storytelling sessions, and another marriage, Sikhidhwaja returns home with newfound appreciation for his wife.
Yde and Olive
A poem from the "Turin, Biblioteca Nazionale di Torino Ms. L II.14". A princess escapes from her incestuous father and ends up serving in the army of a Roman king. She defeats an invading army, earning the king's esteem, and his daughter's love. The king then weds Yde to Olive. Her secret is revealed by an eavesdropping servant, and the king decides to burn both women, until an angel tells the king that God has turned the princess into a man.