How is fasting related to insomnia?
Fasting causes stress and makes your body work off of fat rather than sugar. Sugar is of course related to insulin, which even in normal (non-diabetic) people must be maintained at a certain level (Kaditis et al., 2005). Without a proper level of insulin, your body will upregulate orexin in the brain until you eat (Willie, Chemelli, Sinton, &amp; Yanagisawa, 2001). Orexin will give you artificial energy and inhibit sleep.

References

Kaditis, A. G., Alexopoulos, E. I., Damani, E., Karadonta, I., Kostadima, E., Tsolakidou, A., ... &amp; Syrogiannopoulos, G. A. (2005). Obstructive sleep‐disordered breathing and fasting insulin levels in nonobese children. Pediatric Pulmonology, 40(6), 515–523.

Willie, J. T., Chemelli, R. M., Sinton, C. M., &amp; Yanagisawa, M. (2001). To eat or to sleep? Orexin in the regulation of feeding and wakefulness. Annual Review of Neuroscience, 24(1), 429–458.