Lilja Precision Rifle Barrels - Articles: The Making of a Rifle Barrel
Heat treatment of metal is done by raising the temperature to a point where there is a change in the crystal structure of the metal (an expert can look under a microscope and see what has been done). But the actual crystal structure is on a molecular level. Depending on what you are trying to do, the metal is either quenched to prevent the crystal structure from changing, or allowed to cool slowly.
Crystal structure is different depending on whether it was cast, forged, or tempered in the first place. Button rifling is basically a forging process and can put stress in the barrel, and the heat treatment can remove that stress be bringing it back to it's pre-forged condition.
Queching steel while it is hot hardens the steel, but it can also make it brittle, so you have to know the right temperature for the application. Often a tempered steel piece is added to a forged piece for toughness (wood cutting chisels for example).