Their reproductive systems have matured. The earlier in development, the wider the range paths that might be followed. But early in embryonic development an embryo can go either way, male or female. Without that message, the fetus will develop as a female. With it, it becomes a male.
Development involves a myriad of choices.
Sex is just one. Others are as basic as the number of fingers and the shapes of the limbs, or as subtle as intricate patterns in brain wiring and the subsequent impact on behavior and intelligence. Each one is governed by minute chemical signals, many of them hormonal. Hormonal changes obviously affect adults, too. The levels of hormones involved in these natural and artificial oscillations, however, are enormous compared to the levels that are involved in guiding development.