There are several factors at work to lead you to believe that insulin is "to blame" for your weight gain.
People who have poorly controlled diabetes also sometimes experience weight loss because their bodies are unable to properly convert food into energy. This is because they either are not producing enough insulin or their bodies are unable to use the insulin they produce properly. This food winds up as excess glucose circulating in the blood (resulting in high blood glucose!). Ultimately the body can't use all that extra glucose circulating in the blood and so it is eliminated in the urine.
When your blood glucose runs high, you can become dehydrated as your body works to clear itself of all that excess glucose — which makes you think you've lost weight, but you've only lost water. Then, when you start taking insulin and get your blood glucose under better control, you start over-retaining fluids initially to make up for your dehydration, which makes you think you've rapidly gained a lot of weight. You associate it with taking insulin, but really what is happening is taking your insulin properly is just enabling your body to better use food and maintain a proper water balance.
Also, once you start taking insulin injections and start getting your blood glucose under control, you now have enough insulin circulating in your blood to help the glucose get into the body's cells where it can be used as energy. So the glucose produced by the food you eat is no longer spending time in your bloodstream and being excreted out as urine. You gain weight.
Your high blood glucose may have also made you feel more hungry because not all the food you were eating was able to get into the cells as energy to nourish the cells. Then, you started taking insulin — and continued to eat the same amount of food. Only this time, because your body has enough insulin to process the food you're eating, you gain weight. Before, you were getting away with eating more food because your body couldn't use it properly. But once your blood glucose are in a more normal range, you're just using the food properly — and you gain weight.
Some people quickly come to associate taking insulin with weight gain. They will sometimes cut back on their insulin and let their blood glucose run high once they discover they can lose a few pounds in a few days times by doing so. Unfortunately, when they go back to using the right amount of insulin to maintain good control, they are dismayed to discover that they gain the weight back — and perhaps more — in equally rapid fashion. Manipulating insulin to lose weight is an unhealthy pattern to get into. Letting your blood glucose run high can lead to long-term complications — and up and down weight problems when you try to bring your blood glucose back to a normal range.
When you begin taking insulin, discuss with your health team how to address your weight concerns. It may mean making adjustments in how much you eat. You will need to eat enough to make sure you don't have a low blood glucose reaction, but perhaps not as much as you have been eating to offset the problems caused by having had high blood glucose for a while.