There are different schools of thought on this subject. Some say the sex is "100% Predetermined" - some say the sex is "Predesposed - but influenced by certain environmental factors".
I'm with the "Predesposed" group on this one. That means that a seed, given a normal, average, environment will probably grow up as either a male of female (whichever it is "predesposed" to be). However, certain environmental factors can influence the young, forming, plant to develope one way or the other. This idea goes "hand-in-hand" with the way a human embroyo developes, it starts out with one set of "standard plumbing", then at some point it "decides" to be an "Innie" or an "Outtie" - based, partly, on it's environment inside the womb.
Several factors are said to influence the ultimate sex of cannabis seeds (and seedlings), usually a higher or lower concentration ,or amount, will "persuade" the plant to be either a male or a female, accordingly. These factors include: temperature, humidity, pH factor, available Nitrogen - - - - Have I forgotten any? Do a little "Google" diving and you will find the whole story!