What was impressive though was how long it took and how slow the gain progressed. Because keto calories tend to be so satiating, it almost felt like I had to work at getting my energy balance to stay meaningfully positive. When I'm full on natural fats, it's hard to keep eating. The other interesting thing was, even though I gained some weight, I maintained most of the non-weight related benefits (cognitive, emotional balance). My guess is this may be due to keto calories being almost all fresh, unprocessed foods.
I'd guess you kept the mental benefits because you were still in ketosis. While I'm sure being leaner (if you were overweight) contributes to some mental benefits (body image, feeling healthier), perhaps most are simply from running on ketones.
Even after so many years in strict keto, I still can't tease out where exactly which benefits come from between calorie reduction, ketosis, gut microbiome, etc. I feel like it's definitely a combination of more than one of the above but teasing it out would require too much experimentation and I'm reluctant to 'mess with success'.