it can be in the genetics, or it can be caused by stress, accidental or purposely...some examples of accidentally would be changing light cycles, temperatures, over fertilizing...pretty much any kind of stress that makes your plant "unhappy"
..as far as genetics, some strains are more predisposed to turn hermie and are much more sensitive to these stresses.