Vitamin B12 is involved in the synthesis of melatonin, a hormone that is produced by the pineal gland in mammals and helps to regulate the circadian rhythm and therefore sleep. Thus a B12 deficiency could result in sleep disturbance.
Source:
Peuhkuri, Katri, Nora Sihvola, and Riitta Korpela. "Dietary factors and fluctuating levels of melatonin." Food & nutrition research 56.1 (2012): 17252.
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3402070
This provides a theoretical basis for the treatment of sleep disorders with B12, however the evidence base for the efficacy of such treatment is very small, consisting mainly of low-quality epidemiological studies (case reports). The only well-designed study I could find was by Okawa el at (1997) which did not find any treatment effect:
Okawa M, Takahashi K, Egashira K, et al. Vitamin B12 treatment for delayed sleep phase syndrome: a multi-center double-blind study. Psychiatry Clin Neurosci. 1997;51:275–9.
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4582061