It is really not so much the clothing that teaches Jean Valjean a lesson as it is Cosette herself, as well as her mother Fantine.
As Father Madeleine, mayor of M. sur M., Valjean had tried to live as just, moral, and as generous a life as possible. He felt very ashamed and guilty to learn that someone in his factory had been cast out and treated poorly, which is one reason why he promises Fantine to always care for Cosette. When he goes to Thenardier's tavern to fetch Cosette, he brings her mourning clothing to wear due to her mother's death, a mother she never really got to know. "The Inseparable," as Cosette later dubs it, is a valise Valjean always has with him containing all of the small, black, warm, mourning clothing he brought to the tavern for Cosette. He chose the clothing very carefully, making sure that everything was strongly made and warm. The black fichu, which is a type of women's shawl, was very "stout," meaning heavy and warm; the shoes were very "coarse" and sturdy; the bodice was also "very thick"; there was even a "knitted petticoat" and "woollen stockings" (Vol. 5, Bk. 6,). All of the clothing represents the very first time in Cosette's life that she has actually been cared for and warm. The clothing also represents the first time in Valjean's life that he had someone to love. After he was released from prison, he searched many years for his sister and her seven children he stole the loaf of bread for, but with no luck. We especially see just what Cosette and Valjean mean to each other and just how much her new marriage to Marius has devastated him because she no longer belongs to him when the narrator describes how they had walked away from Thenardier's tavern hand in hand while she carried her new big doll and her gold coin, adding, "She had laughed ... she had no one in the world but him" (Vol. 5, Bk. 6, Ch. 3).
Hence, Cosette taught Valjean real love while Fantine taught him more about his human failings.