Answer
The pipeline that maps fluctations in magnetic fields to mental activity is long and complicated. The key component from the perspective of a neurophysiologist is that neural activations cause changes in blood flow, which are detected with magnetic fields. The primary mechanism for this is activity-dependent vasodilation.
How Does fMRI work?
A complete answer to this question is probably impossible in any format shorter than a book. Consider: the first sentence has to introduce quantum mechanical spin and the last sentence has to say "and now we can reliably and quantitatively observe complex mental activites evolving in time". Fourier transforms are introduced in between for convenience's sake.
For the purposes of this question, I'm going to treat the MRI portion as effectively magical – let's just assume that we have a method to sensitively detect changes in the magnetic properties of biological tissue.
From there, the chain of logic is straightforward enough that Linus Pauling came up with the idea in the 1930s while playing around with cow's blood and magnets.
The key insight is that oxygenated blood has different magnetic properties than deoxygenated blood, thanks to the iron atoms our blood uses to bind oxygen.
Therefore, we can use our magical magnetic-properties-detector to visualize the flow of oxygenated blood in biological tissue.
Blood Flow in Neural Tissue
To the delight of cognitive neuroscientists, the blood flow in neural tissue happens to be quite informative!
A key reason why is that neurons are highly specialized and dependent cells – one might view them as the "wise men with skinny arms" of the body. They are incapable of making their own food from raw materials or of storing food for any period of time, and so must be spoon-fed glucose, a sort of pre-chewed food, by the intricate and responsive vasculature of the brain (pictured below).
Plastic cast of the cranial vasculature. From Zlokovic and Apuzzo, 1998. No wonder aneurysms and strokes are unavoidable!
When neurons fire action potentials, a variety of energy-consuming processes are activated. For example, the flow of currents slightly changes the resting membrane potential, which must be restored through an expenditure of energy. To get a sense of the scale of this energy use, consider that the brain, which weighs less than a pound, uses a full 20 percent of all calories consumed by the body!
Energy consumption is particularly acute during periods of high activity. Even though we do use 100% of our brain, we use some of it more than other parts at certain times. As different parts of the brain become more active than others, the vasculature responds at a columnar scale to make sure energy is available where it is needed.
This of course means that oxygenated blood will move into an area, then rapidly become deoxygenated. The incredible fact that powers fMRI is that we can observe these changes because the oxygenated and deoxygenated blood have different magnetic properties.
Physiologists might be interested in the biochemical mechanism of this response. The smooth muscle of the vasculature, like most smooth muscle, is controlled by chemical signals, like nitric oxide. These signals cause the muscle to increase or decrease the diameter of the blood vessels, changing the flow of blood in much the same way that we change the flow of water in our homes by twisting the knobs on our sinks.
Even though nitric oxide is a neurotransmitter, release of NO from neurons isn't believed to underlie the vascular response. Instead, the glia, the brain's underappreciated janitorial staff, detect the overall level of neurotransmitter release through reuptake mechanisms. When reuptake is high, levels of calcium increase, leading to increased nitric oxide synthesis.
Caveats to fMRI
The fore-going has hopefully indicated some of the issues with using fMRI to study neural activity.
The fundamental signal being measured is blood, rather than neural activity. Even generating the signal requires the coactivation of many neurons, and the resolution is limited by the scale on which blood flow is regulated by the vasculature, around a cubic millimeter. If that sounds small, consider that there are on the order of a million neurons in that much tissue.
As you might expect, connecting such an abstruse measurement as the magnetization of blood to abstract mental activity is a complex process, involving physical, computational, and statistical transformations of the data, to say nothing of interpretation.
Because of this, very few people understand every step of the process. And the details are important!.
Despite all of these concerns, fMRI stands as one of the most effective methods for connecting psychological phenomena to physical processes.