Penal Legions are regiments of the Imperial Guard composed solely of criminals. Instead of serving a very long sentence these men and women have been given the once-in-a-lifetime opportunity to fight and die for the Imperium, thereby wiping away their past sins and allowing them to achieve the Emperor's peace. The Penal Legions are most probably inspired by similar Soviet units in World War 2, though prisoners have been fielded by many desperate armies over the course of history. France conscripted criminals to fill the trenches during World War 1 for example while medieval galleys were sometimes rowed by convicts.
Needless to say, Imperial commanders tend to use Penal Legions as an expendable resource, even more so than normal regiments. Penal Legion soldiers hooked up on chems and sent on suicide missions is a major source of Grimdark, which 40K runs on.
Crimes punishable enough to be sent to the Penal Legions includes murder, minor heresy, cowardice in battle, desertion, etc. They are often used to test enemy defenses and drown the enemy in blood and corpses. New troops have their heads shaved and tattooed with unit insignia, and explosive slave-collars are put around their necks. Contrary to popular belief, the collars are a disciplinary device rather than a means of turning the troops into human bombs; the blast is directed inwards, killing only the wearer. The collars are controlled by personnel accompanying the force, and are detonated only to restore discipline. As well as the collars, Penal troops are sometimes equipped with Frenzon dispensers. Frenzons are the chems and drugs which cause the user to become as angry as an Angry Marine and as fearless as a Necron. You know what also uses Frenzon? Eversor Assassins, so now you know what makes these drugged-up assassins so unhinged.
Troops sentenced to the Penal Legions serve for life. Most die in their very first battle, herded into the enemy gunfire and dying by the hundreds. A few, the born killers, somehow beat these merciless odds and survive through numerous battles. In extremely rare cases a penitent might be granted the Emperor's forgiveness in a way other than dying in battle, by performing some incredible act of battlefield valor. These redeemed men then enter the Imperial Guard as regular Guardsmen, which is not much of an improvement to be honest. (It is, see below).
Penal Legion units are formed from convicts, generally from those shipped to one of the Imperium's Penal Worlds. In fact they are the only prime export from Penal Worlds, whose populations consist of criminals from throughout the Imperium.
Because the capital crimes in the Imperium vary from planet to planet, convicted criminals serve as an inexhaustible supply of recruits for the Penal Legions. For 'petty' crimes that do not warrant immediate execution, miscreants in the Imperium are sometimes shipped to a nearby Penal World. From there some may be formed into Penal Legion units. Sometimes Mutants are found in Penal Legions as well, such as Abhumans, like Beastmen.