What you're talking about is transsexualism which is based on a psychiatric diagnosis of what used to be called gender identity disorder (up to the DSM-III) and is now called gender dysphoria. This is a very rare condition (rarer than heterochromia, or having eyes of different colors) related to body dysmorphia, which is a mental illness as you say. These people (transsexuals) try to escape the very negative feelings they have about their sex by trying to change their bodies and present as live as the opposite sex.
The vast majority of "trans" people however are transvestites. They have rebranded transvestism as transgenderism and use the same hormones (rarely also surgery) as transsexuals, but their motivation is quite different: they gain pleasure (called euphoria) from cross dressing and imagining themselves as the opposite sex. Many of them (autogynephiles) are sexually aroused by the idea of themselves as the opposite sex. They are usually heterosexual while transsexuals are homosexual.
In order to try to gain social acceptance for their transvestic fetish, the transvestites essentially invented a religion whereby they could garner sympathy for the mental illness experienced by transsexuals (which they don't have) by claiming the idea of a gender identity being something undetectable by science (like a soul or a chakra) which can potentially be different from your actual sex. According to this ideology, it is the ineffable gender which makes you a man or a woman, not your actual sex (hence all the slogans of "trans women are women", "trans men are men", etc). The proof above shows that even if you believe that this gender spirit exists (which is a leap of faith and unprovable), the definition that transgenderists give of the criteria to actually be transgender is flawed.