The basic way its explained with nurse training, is that if your body has pathogens (illness) to fight off, it raises its internal thermostat to kill them... which also makes you feel awful, feverish etc. Once you are on the mend, your thermostat resets itself to normal, meaning you are now too hot, and start sweating.
I've never been too sure why artificially lowering your temp with paracetamol, say, doesn't make the illness last longer... maybe sqad knows.