The child's sex is fixed at conception. As with any complex system, there can be failures to complete, in this case incomplete development of a male or female phenotype alone one or other of the (only) two pathways. Sometimes this appears in external genitalia at birth; such people (a tiny percentage of all DSDs) are called "intersex". There are dozens of DSDs, some of which go unnoticed, except when trying to conceive/father a child, and sometimes not even then. Most DSDs are found in men. I have come across only two or three cases in the literature of partial development of primary sex characteristics of one sex along with complete development of the other; one was of a man had one normal testicle and internally a partially formed ovary (with eggs), fallopian tube, and uterus internally. There was no doubt he was a man: he fathered a child.
That's because trans and "intersex" are unrelated phenomena, which in turn is because sex and gender are not the same thing. As lots of people with DSDs will tell you. If you can be e.g. otherkin, agender, demi-girl, genderqueer, genderfluid, etc., but there are only two biological sex classes defined ultimately by the two types of gamete, something else must be going on. Moreover, inappropriate surgeries performed on intersex individuals, often as children, are one thing: inappropriate surgeries performed on people, sometimes as children, who "feel" they are the opposite sex—whatever that means—are quite another.