There is a wonderful example in Mozart's Le nozze di Figaro (The Marriage of Figaro). Figaro is a valet (formerly a barber) who is about to marry Susanna, maid to the Countess. Another character is an adolescent page boy, Cherubino, who desires the Countess. The thing is that the role is played (sung) by a soprano en travesti ("in trousers") that is to say, dressed as a boy. The role is both immensely funny, as Cherubino's emerging desire for all women and especially the Countess is what he (she) sings about a lot. But it is also rather sexy and provoking because he is really a she, which makes it all a bit perverse (by the standards of the time).
The Guardian has an excellent music section and part of it is streamed operas from Glyndebourne. You can watch, for example, an excellent production of Le nozze di Figaro until Aug. 31. Here is the link. The part of Cherubino is played by Isabel Leonard who is charmingly boyish. Here is a photo from the production. Isabel Leonard, in character, is on the left, Susanna, played by Lydia Teuscher is on the right:
And here is a link to part one of the video. Cherubino enters at around the 23:20 mark.
But how did this odd tradition begin? Originally travesti roles were actually sung by male castrati. Dating from the 16th century and dying out in the 19th century, young boys were castrated and as they grew up, their voices did not change and they were able to sing soprano or mezzo-soprano parts, but with great power and flexibility. Thus there was the odd situation of a male leading role sung by a male soprano. By Mozart's time the castrati were being replaced by women singing the same roles and dressed as men.
In the history of theater (of which opera is a part) there are many other examples of actors playing roles of the opposite sex. In Shakespeare's time, for example, the parts of women were played by boys as it was considered immoral for women to appear on stage. In Monteverdi's Orfeo, one of the earliest operas, the leading female roles of Eurydice and Proserpina were both played by castrati. But from the 17th century on, it has also been common for women to portray male roles on stage. One famous example is the actress Sarah Bernhardt in the role of Hamlet:
There is a recent collection of essays by musicologists on travesti roles that looks quite interesting. One of the papers is by Mitchell Morris, with whom I took an excellent seminar on Shostakovich. One hopes that it goes beyond the ideologically predictable position that, as Amazon says, "addresses the ways in which opera empowers women by challenging conventional gender hierarchies." Ah yes, those pesky conventional gender hierarchies that people have been nattering on about for the last forty years. Just looking at the history of travesti roles in opera and theater shows that things are a bit more complicated and interesting than that.
Let's end with a modern example. In Richard Strauss' Ariadne auf Naxos the role of the composer is sung by a soprano, originally Lotte Lehman. In this clip, also from Glyndebourne, the composer is sung by Kate Lindsey.