I have been kind of deep down these rabbit holes of how it works physically. It comes down to some kind of simple principles. Exercise gives your brain more blood. Lifting puts static pressure and conditions vessels and such. Many pro-brain-health hormones get released. The physical actions force a degree of indirect distraction that lets your sub-conscious work as well. These things all combine to promote brain health and problem solving. The brain uses a ton of energy so the blood flow just keeps it well fed.
E: it also makes sure junk from metabolic processes are cleaned up etc.