Can I replace a 9spd freehub with a 7spd one? On my commute this morning I established that my freehub needs replacing.  There's obviously something wrong with the ratchet mechanism, because it intermittently refuses to engage.

My existing setup is a Mavic Crossmax rear wheel (circa 1998) which originally hosted a 9spd cassette.  However I have been running it with a 4.5mm spacer and a 7spd cassette which has been working fine.

Can I replace the freehub with a 7spd one, or will that simply not work?  Is the wheel somehow dished specifically for the 9spd width?  Should I instead just buy another 9spd freehub and continue to use the 4.5mm spacer?

I did look on Sheldon's website, but couldn't find this exact scenario.
As you suspected, you may not run a 7 speed free hub with a 9 speed hub shell.  You will need a new 9 speed free hub, and continue to use the spacer ass you have been.

Hubs are not generically sized.  Each model is sized for the number of gears it is expected to work with.  Replacing the freehub will mess with your dropout spacing, or the position of the gears in relation to the wheel, or both.  It can also prevent the bearing adjustment from working properly.