Is it legal? Ask a lawyer, not the Internet.
Is it right? Yes.
If he had stolen basic sustenance (bread, meat, veggies, water, etc) then most people wouldn't have a problem, because his situation would be taken into account and nothing would come of it. BUT, he did NOT steal a basic necessity of life, he stole a can of soda - a non-necessity. The Jean Valjean argument goes right out the window.
Does the child need to be punished for this action? Of course. So now the issue becomes: what punishment will instill in him the urge to not do this again? If suspension isn't an option, then you look at detention. Detention isn't different enough from his normal life to have any impact on his future decisions, so the school wisely tossed that option out. Did he want to clean? No? Perfect! A punishment can't be something he WANTS to do or else it becomes ineffective. The only thing I would have added to his punishment was a little recorder repeating the message:
"You're being punished because of the decisions you have made."
You add this to reinforce the fact that he was the one who was responsible for what was happening to him at that point: if he hadn't stolen the soda then he wouldn't have to clean toilets. There is a cause/effect relationship here that the child obviously hasn't grasped yet.
The first measure of a punishment needs to be: "IS IT EFFECTIVE?" not "Is it too much?"
Now, should his environment be taken into account to determine if he should be disciplined? Absolutely not. Part of the issue here is that BECAUSE of his environment he has not received adequate discipline. The proper response here is not to give him even less than what little he already received, but to establish a proper level and to maintain consistency to help this child grow into a fully-functioning adult. EVERY child has issue growing up, some have more than others, but the test of a child is to overcome whatever issues they have experienced and become a well-balanced human being.
He burst into tears NOT because he was being punished but because of his life situation. He probably DID want his mommy back, but he needs to get it through his head that it's not gonna happen - no matter how much he misbehaves, cries, screams, or bitches. He needs to understand that he was dealt a tough hand but he has to play it as best as he can. I think ToastiestZombie needs to go scrub some toilets and realize that it's not "degrading" or "humiliating", it's not pleasant but it's a necessity of modern society and somebody has to do it.