It certainly isn't a matter of choice, but there is no firm evidence that it is purely genetic either. There may be other factors such as the mother's hormonal state at a critical stage of the pregnancy or a genetically-linked susceptibility to environmental factors.
It is often thought that gender is fixed and cannot vary, but whilst that is almost certainly true, it is possible to have a gender which switches randomly between two points or which 'wanders' over a limited range. That is a 'fixed' gender condition; even though the gender itself changes, the condition remains constant and unchangeable. Many transgender people report that there are some days when they feel gender dysphoria stronger than others without any obvious external cause.