heey there. i'm nooot sure whether it causes one to gain weight in a direct way - probably not. ie, not like if you have a hypothyroid, it reduces thyroxine levels, and hence your matabolism n then results in possible weight gain.
I would , though , suspect that because B12 deficiency usually causes alot of fatigue/tiredness/lack of energy all the time resulting in moving around less, more sleeping, less physical activity etc and if you're still eating the same amount of food, or maybe even more - then this can result in some weight gain.
I have had SEVERE b12 (plus iron and folate0 deficiency, but it didn't cause any weight gain cause i had a malabsorption syndrome. but I can def tell you that those deficiencies causes you to be tired n feel lethargic most of the time - did to me anyway.
hope this helps