In insects the mechanism is fairly well understood. A fly with XX chromosomes will be a female.
However, an embryo that loses a Y chromosome still develops into what looks like an adult male, although it will be sterile.
It’s thought that bilateral gynandromorphism occurs when two sperm enter an egg. One of those sperm fuses with the nucleus of the egg and a female insect develops. The other sperm develops without another set of chromosomes within the same egg.
Both a male and a female insect develop within the same body.