I've been going through similar recently due to wider things, but certainly low thyroid hormones cause what you describe, as too ive found does slight anaemia / or non anaemic iron deficiency. I believe low b12 can also do this and low vit D.
I believe the brain can be viewed like a muscle, needing oxygen, blood, nutrients etc etc as well as a mental work out (CBT, thinking training, chess, mindfulness what ever). I believe this as following a thyroid dip which makes my brain very slow (word finding issues, memory, executive function) simply adding the thyroxine isn't enough - I have to "exercise" it. Depression can cause exactly the same.
Mh is awful as it erodes your personality; unlike a broken leg which doesn't govern your sense of humour etc. so it's really tough to heal. Obviously drugs help but I feel they're only half of it. My belief is the brain needs physio as well. I teach children with ASD (now ASC) but I don't feel I teach them as such. It's a lot of therapy both body and mind.
However, what is amazing, is that the brain is plastic. New skills can be learnt (eg taking up a hobby, sport etc) but new thinking skills an be learnt too. I took up martial arts at the age of 28. I think exercise helps due to extra oxygen up there, but breathing can do this too, yoga etc.
I'm not saying I'm great at practising what I preach but repeated recoveries from brain mush and depression and severe anxiety since the age of 20 have given me huge faith in the power of the mind over mind!
A psych did say to me "these things generally get worse each time" when trying to persuade me into sertraline (which did help a lot) but I now don't believe him. Or I don't believe it's an insurmountable thing. I think we maybe get less resilient with each new episode or maybe as we age?
I think I could be different with bipolar, at the same time I know people who are finding they are more in control of their bipolar as they age.