Two basic kinds of cross-dressing exist: the paraphilia (called 'transvestism') and actual cross-dressing.
Cross-dressing, for the layman, can be described as a sort of cosplay. For gay people in the days of persecution it was a sort of burlesque, from the Latin-Romance, "burla" = jest or mockery. A way of letting out some steam, let's say, of expressing the inexpressible. Although for many it was a way of expressing what had always been drilled into their heads since earliest childhood: that they were "sissy", "girlish", "unmanly", that only girls could love men, so it manifests the deep (uncnsc.) wish to be a woman in order to have access to men without guilt or fear. Fantasy is the spice of life.
Also, depending on cultural context, non-homosexuals would perform it. Think of theatre centuries ago, when it was thought "improper" for women to perform. Men had to act the women parts.
Transvestism is not a homosexual thing. It's a kinky thing, and it's related to heterosexual men wearing, say, panties under their work clothes. As such, it is a healthy part of sexuality, as everyone, in a way, has deep-set fantasies to aid in arousal, even though they leak out into our daily lives, either knowing or unknowingly. If we repress them they come out as symptoms, character traits, mistakes (the Freudian slip or lapsus linguæ). For all we know, freedom and self-acceptance, together with its mirror version, the acceptance of others, are conditions for health and happiness.