The primary purpose of flux is to prevent oxidation of the base and filler materials in the short time between cleaning and soldering. Tin-lead solder, for example, attaches very well to copper, but poorly to the various oxides of copper that form quickly at soldering temperatures. This applies to lead and brass too.
Flux is a substance that is nearly inert at room temperature, but it becomes strongly reducing at elevated temperatures, preventing the formation of metal oxides. Secondarily, flux acts as a wetting agent in soldering processes for lead, copper and brass.
Without flux the solder does not firmly attach to the lead or copper foil and often forms sharp peaks.
Flux, an introduction
Fluxes, a description
The Purpose of flux
The action of fluxes