I think it can depend on the timing of the scan (earlier is less likely to be as accurate) and the baby's development (for example, if you only have one scan at 18 weeks but your dates are wrong and it's really 16 weeks it might be too early to tell clearly) and also there is no accounting for deformities/abnormalities of the genitals (not common, but they do happen). I know someone whose baby girl was diagnosed with genitals that were deformed via u/s before birth (but still knew she was a girl) and required surgery afterwards.