So insomnia can cause weight gain because, essentially you are sleep deprived when you do have insomnia. Now sleep deprivation in general causes an imbalance of hormones that control your appetite. You have two hormones that control your appetite, leptin and ghrelin.
Leptin is a hormone that lets you feel satisfied after meals, and ghrelin is the hormone that makes you feel hungry. So you have an increase in ghrelin, so you're more hungry and you have a decrease in leptin. So you're more satisfied after meals. So you tend to eat more and since you are less satisfied after meals you tend to eat even more on top of that to help you satisfy your hunger.
Now there is an alteration in your metabolism when you're sleep deprived, so it is harder to lose weight because your metabolism is not working at its peak level. So in general insomnia will cause weight gain through the effects of sleep deprivation.