You get affected by hat magic and turn into a little girl, your spare body mass is used to produce hats of spectacular quality. You keep one of the hats as your own and enter the fray as a new Touhou character. Ever wondered why Youki, Myouren, Rinnosuke and Unzan all lacked/are popularly depicted without hats? That's how they kept themselves male for so long. Merely touching a hat can turn you into a girl.
In addition, Touhou characters have sex by gently patting each other's hats while hugging and whispering words of love to each other. Truly hat sex between two elegant little girls is the purest sex.