There is no definitive scientific answer to why some people are transgender.
Being transgender is not due to bad parenting, not going to church, or what a mother ate during pregnancy. All of these are misconceptions that the public leans on because they have little understanding of transgender people.
Gender identity, anatomical sex, and sexual orientation are determined while an individual is in the womb. Although the anatomy happens in the first six weeks, gender identity starts actualizing at around six months gestation. It is at this point that the brain feminizes or masculinizes.
A testosterone surge will stimulate the fetal brain to develop in a male direction. Without the surge, however, the fetal brain will develop towards a female direction. With transgender individuals, the genitals will not match the brain direction. Therefore, these individuals will feel trapped in a different body.