I do believe that's the plant ensuring its survival. If the plant is at a stage where it's in or outside the harvest window the plant may try and produce a seed to ensure that it's species survives. I may not have done the explanation any justice but there are other factors too that may be related to the environment.
How Does a Feminized Cannabis Plant Produce Seeds?
For you to be able to create a feminized seed, you must be able to induce male flowers in a female plant. There are two ways in doing this, its either you would put adequate stress to the feminized cannabis plant through light stress, mechanical or some environmental stress or to just let the cannabis plant to stay in the flowering stage by not changing the light hours. This process is quite complicated and dangerous because you might incur damage to your cannabis plant if done incorrectly that is why you need to have sufficient knowledge in doing this.
These stresses that you can impose to your cannabis plant just to produce seeds may lead to hermaphrodites, where your end result will not have a distinct quality of a male or a female. There is also a big chance of getting hermaphrodites as your end result if the process is not carried out correctly. The ideal way of producing feminized seed is through the alteration of the hormones of the cannabis plant through the use of inhibiting plant hormones to produce male flowers.
Hope that helps a bit.