There's a chance that the folate caused these side effects because it increases the production of nitric oxide, a gas.
Nitric oxide is good for many functions, but too much can be toxic .
Excess nitric oxide is implicated in migraine headache, and numerous neurodegenerative diseases. Even anxiety, depression, bipolar conditions are associated with it.
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6303682/
There are so many substances that increase nitric oxide production : Probiotics, Omega 3, vitamin C, vitamin D, amino acids such as arginine and citrulline, etc.
The body will produce nitric oxide to fight infection.
Fortunately, B12 is a good inhibitor of nitric oxide production. Even ibuprofen inhibits it somewhat. Riboflavin and melatonin are inhibitors.
Excess nitric oxide interferes with serotonin production in animal testing. That may be one cause of pain and insomnia.