In modernity there are a lot of people who transition from one gender to another, identify as both genders, or don't feel like they have a gender. But all of these identities seem like they sprung up out of nowhere in the last two centuries. Were any historical people recorded as identifying as one of these groups?
As a follow-up, how were they treated in various cultures, and what was their role in society?
There is a brief case study of a person identified at birth as a woman, but later lived as a man in colonial Virginia, 1629. Thomas Hall (birth name Thomasine) lived in England as a woman, but after moving to Virginia in the 1620s, he began dressing and living as a man. Kathleen Brown's Good Wives, Nasty Wenches, and Anxious Patriarchs deals with the case in Chapter 3. The original court case that she analyzes is printed and available online for free here.
The book you may want to consult on concepts of gender fluidity from the Classical era to the twentieth century is Thomas Laqueur's Making Sex: Body and Gender from the Greeks to Freud. Among his many points is an argument that people in the medieval era believed that gender existed on a continuum, with women (representing cold and wet) on one end, and men (hot and dry) on the other. There was a belief that people could lose or gain manliness (or femininity) through imbalance of the humors, and become more female/male. His argument is a little strained at points, but it is a good jumping off point. Another work worth looking at in general is Lyndal Roper's Witch Craze which covers issues of sex, gender and age using evidence from sixteenth century Germany. Besides being a good work on gender, it is also an excellent and entertaining read on witchcraft.