This is not even close to being universally true. It's not uncommon for the powder to not be completely burned when the bullet leaves the barrel, say nothing of before it leaves the case.
In fact, that statement is closer to almost never true than almost always true.
Typical loads in typical cartridges like 9mm, 40SW, 357mag, 44mag, 45acp, 10mm, 357sig, etc, etc virtually never burn all of the powder before the bullet exits the case.
The only time that statement is generally true is for small charges of fast burning powders, most generally in very light, or "target" loads in revolvers.
You confuse the issues of (a) how much of the powder will be burned and (b) of the powder that combusts, when is the combustion process completed?
As a matter of physics, the
time at which pressure peaks and then begins to decay marks the end of combustion. Back in the days of copper crushers, all we knew was the
level of peak pressure, but not its time; with modern equipment, we can obtain a time series of pressure for the entire time of bullet travel down the bore. For virtually all rounds in virtually all calibers, gas generation (i.e., increasing combustion chamber pressure, i.e., combustion) is complete at or before the commencement of bullet movement, or before the bullet has moved a small fraction of bullet length. After that the force that results in bullet acceleration is entirely the result of the residual combustion product gas pressure, post combustion.
(To use just one example: the peak chamber pressure of an M2 ball round fired in a U.S. M1 rifle is about 48,000 psig. However, by the time the bullet reaches the gas port (short of the muzzle), combustion chamber pressure is down to the range of about 2,000 psig. Pressure is decreasing because combustion chamber volume increases as the bullet moves down the bore, but no more combustion product gasses are being generated (because combustion is long since complete). In fact, combustion chamber pressure has been decreasing since the bullet began to move, but so long as chamber pressure force on the bullet exceeds the coefficient of friction of the bullet in the bore, the bullet continues to accelerate.)
The fact that for some loads some of the propellant never ignites does not mean that combustion was on-going at the time the bullet exited the muzzle and the combustion chamber was vented to the atmosphere. At the risk of over simplification, it usually means that the propellant was too slow for the round in question, such that those particles more distant from the primer flash failed to ignite because, by the time they were exposed, chamber pressure and temperature were too low. In many cases, usually involving revolvers, unburned propellant is also linked to inadequate crimp.
Likewise, muzzle flash is not a manifestation of the primary combustion of propellant. Again simplifying a bit, it is the result of the flashing of combustion products suddenly exposed to atmospheric pressure (and a comparatively oxygen-rich environment). This is why muzzle flash can be controlled (to some extent) by controlling propellant chemistry.
Last item: it is usually observed that, given a certain charge, muzzle velocity goes up as barrel length increases (at least up to a point). This is sometimes taken to signify that the longer barrel allows more complete combustion than the shorter barrel. However, the fact of the matter is that the longer barrel exposes the slug to the positive force of the compressed combustion product gasses for a longer time. You can demonstrate the same phenomenon using compressed CO2 as the acceleration medium, with no powder or combustion involved. Hold the volume and pressure of the injected CO2 constant, and you will still see increased muzzle velocity with increased barrel length (again, up to a point).
Sorry; end of lecture.