By this late stage in the story, Jean Valjean has become a Christ-like figure who's put aside all his bitterness and righteous anger to embrace forgiveness. As he lays dying, he wants to pass on the Christian message to those he cares about most, so that they might learn from his mistakes and realize that life's too short to be spent hating those who've caused us harm.
Like Valjean, Cosette has every right to be bitter given the many privations she's has to endure in her short life. Most of the problems she's encountered over the years have been in some way related to the greedy, callous Thenardiers, who neglected her when she was younger, preferring to spend money on themselves instead of her upkeep.
But as he lays upon his deathbed, Valjean urges Cosette to forgive them for their wickedness. He knows from personal experience that this is a prerequisite to moving on. So long as Cosette is eaten up by bitterness and hate, she will be unable to do this and so will remain stuck in her unhappy past. And this is the very last thing that Valjean wants for someone he cares for so deeply.