She's got a child she is paying for, how is that a problem?
Anne Hathaway was playing the character of Fantine, a single working-class woman in early 1800's France. Following the novel's timeline set by author Victor Hugo, she's fired from her workplace in 1822.
In 1822, her supervisor discovers that she has an illegitimate child. It would be one thing if she was married and had a child that she was paying for, but having children while unmarried was highly scandalous at the time. You could parallel it to the outcome of Boy Scouts v. Dale. A troop leader was kicked out because he was gay and this was legal and viewed as an ok thing to do because private businesses are allowed to exclude a person when the presence of that person affects the group's ability uphold social viewpoints.
Even though that was a case that took place in the United States in 2000, certainly a different time period than 1800's France, it is the same general idea that the supervisor had at the time: they didn't want someone on staff who clashed with what was considered socially acceptable at the time.
It wasn't having an illegitimate child that caused her firing. It was because the foreman wanted to have sex with her and she refused, while maintaining a pure and virginal behavior. The women she worked with resented her for this, seeing it as a rebuke of their own less pure behavior. They were gleeful to discover she was not as pure as she'd pretended. But the real problem was the foreman--when he found out she'd been sexually active but still rejected him, his ego couldn't take it so he fired her.