There aren’t many animals that can spontaneously change sex, but it can happen for some. For example, clownfish are known for changing from male to female during the mating process. Hens, on the other hand, don’t do it in order to procreate.
A female chicken is born with one ovary and one inactive gonad. That gonad has three options for developing: to become an ovary, a testicle, or a combination of the two called ovotestis.
If there’s a cyst or tumor on the hen’s ovary, the gonad will activate. If it develops into a testicle or an ovotestis, a hen will experience the release of male sex hormone androgen, which may result in a sex change.