Question as stated. I haven’t seen anything to suggest it was punishment for an offence (he didn’t seem to have ever committed any) or that he was only useful for that particular assignment (he was one of the best), so why?
Out of universe
If you look at 20th century military, especially conscripted ones which is what First Order had - for example Soviet Army, "painting fences", "digging latrines", "cultivating potatoes" was a standard duty for soldiers.
Someone has to do it, right? And privates are free, no need to budget for sanitation
Boredom is the enemy of the private. Sanitation or any other makework is a good cheap solution. There are stories of privates digging holes one day and filling them up next day.
According to the "Before the Awakening prequel book, the timeline was the following:
- Finn was a cadet in training
- Then, he was called up to deploy first time ever, with Captain Phasma. At that time he was told he was becoming a real stormtrooper, and never saw battle yet
- That deployment was to some Outer Rim system, and was basically urban pacification (translated: they were ordered to shoot the leaders of striking miners)
- Immediately upon the end of THAT event, Phasma loaded them all up on board SD, and headed to pick up Kylo Ren on the way to Jakku.
Captain Phasma watched FN-2187 on the monitor in her quarters. He’d stopped firing, stopped even moving, and was just standing amid the ever-changing field of moving figures.
She sighed. She’d had such hope for FN-2187. He had shown such remarkable promise. He had shown the capacity to be special.
She picked up the orders on her desk and reviewed them once more. They’d already made the jump to hyperspace, and she knew it would be less than an hour before they reached their rendezvous point to take on their new passenger. Kylo Ren had already transmitted the coordinates for where they would be headed next.
She switched off the monitor. He’d be part of the detail when they reached the landing point on Jakku, she decided. Perhaps when someone was shooting back at him, he would understand what it meant to be a real stormtrooper, what it meant to serve the First Order, body and soul.
What that means is that Finn was on the Starkiller not even as Stormtrooper, but as a cadet in training.
So assigning cadets in training to Sanitation seems logical for out-of-universe reasoning above - they are the most useless of soldiers around yet.
Here's how training for cadets is described in the prequel:
They were stormtroopers, but they weren’t quite, not yet. They were cadets, and as cadets they had additional duties aside from their training. Those duties covered everything from maintaining the armory to performing minor repairs on equipment to quite literally moving equipment from one location to another, often by hand but frequently with the assistance of the heavy-lifter droids, when whatever was to be moved was too big to be moved manually. They mopped the floors. They emptied the trash. They worked in the galley preparing meals.
Another theory (UPDATE!!!)
It just occurs to me - the "I was in sanitation" line given to Han was the only actual canon evidence of "Sanitation" job. But was it the truth"?!?!
Finn is always trying to create a positive impression of himself with the Resistance, from the get-go:
He tells Poe that he's rescuing him because that's the "Right thing to do" (with Poe quickly seeing through the fib: "You need a pilot!")
He tells Rey that he's Resistance (she buys that because she's a romantic 19 year old still playing with X-Wing pilot helmet)
He tells Han that he's Resistance (that one lasts about a minute - Han was not a romantic 19 year old even at 19 :)
As such, I am pretty sure telling Han "Hey, I was 1% of my class, model stormtrooper, groomed for promotion by Captain Phasma" isn't high on his list of brand management plans. Far better to pretend to be a lowly "sanitation" worker than top-flight cadet that he really was.
I asked a separate question to verify if we have any proof he was telling the truth: Is there any canon evidence that FN-2187 actually worked in sanitation?
Although @DVK 's answer is much better than mine, I'll still add my €0,02. Disclaimer: I haven't read the book, in which both Phasma's and Finn's characters are apparently fleshed out a bit more.
I would interpret it as Finn using as a euphemism for being part of a stormtrooper force who basically exterminated an entire village, the same way that Tony Soprano claimed to be in 'waste management' shortly after killing somebody. In this context, 'sanitation' would actually refer to the janitorial duties he had, instead of 'sanitizing' a village, but still it would not make any sense for him to reveal that he was a stormtrooper at that moment.