I read about very harsh punishments for menial violations. Didn't these men have better prospects than a job with such harsh punishments and low wages?
In a word? To escape a desperate cycle of poverty.
The British army in this time period drew the vast majority of its recruit from unskilled labourers, at Waterloo for example more than half the British troops were farm labourers or unemployed textile workers. Its also a reason why the Irish were so over represented in the army. The Duke of Wellington's army at Waterloo was over 40% Irish. The Irish peasantry was relatively poor and so army life appealed to the Irish as a way to escape the poverty.
The fact it drew from the "dregs" of society gave the British army a poor reputation, especially among the upper echelons of officers (commanders) who tended to be well off aristocrats. Wellington even declared that his army was made up of the "Scum of the Earth." A British recruiting officer operating in the 1830s expressed a similar sentiment:
it was only in the haunts of dissipation or inebriation, and among the very lowest dregs of society, that I met with anything like success
Army life wasn't all that much better though. An infantry solider got about "one shilling a day" where as a cavalry man could expect slightly more. But it wasn't always paid in full or on time. Plus deductions could happen for: messing, laundry, kit replacement, hair-cutting, barrack damages and hospital treatment, if necessary. Diseases like tuberculous were rampant because of close, uncomfortable quarters and soldiers being routinely overworked.
Your daily ration consisted of: "a pound of aged, dried meat, a pound of bread, flour or biscuits and a pint of wine or one-third of a pint of spirits. Vegetables and fruits supplemented the diet as available, with peas and onions the most frequently available. Each mess (generally squad level) carried a camp kettle with the lid used for frying and the pot for boiling and stewing. On the march, each man carried three days’ worth of rations."
There were opportunities for advancement, which brought more pay and perks. But those weren't always attainable for a lowly infantryman, and the very top ranks remained dominated by landed officers. Though certainly those who served for a long time could find themselves with a commission or rising to higher ranks like captain; especially in wartime when sale of commissions were relaxed.
So why did soldiers join? Well besides the above mentioned escape from poverty. For some it was to escape circumstances at home such as the law. For others it was seen as a manly thing to do, and they may have been lied to by the recruitment officer or recruited under the influence of alcohol. For a smaller minority it was for a sense of adventure. As Britain's empire increased and the army went on bigger empire building projects it became easier to sell the army as a means of adventure to young men, but that's much later and towards the nineteenth century.
Edit:
Just want to add that this mostly applies to the British army at the beginning/through out the Napoleonic wars. Obviously conditions could and would vary depending on campaign, commander, etc.
Sources would be the section on the British army in the Blackwell companion series to Britain in the 18th century and 19th century. As well as relevant sections on the British army from Jenny Uglow's In these times And Waterloo by Alessendro Barbero.
Edit2:
Changed wording on a few sections to make stuff clearer.
Side question: It's common knowledge that the British navy impressed (essentially enslaved) free citizens into service liberally. Did the army practice this same...practice?
Do we know what percentage of the navy (or army of applicable) was impressed?