He simply lost the will to live. There is no medical reason given, and he was, as an able bodied male, a bit too young to die of old age complications. It's possible he did have an undiagnosed medical condition, but the story does not touch on that. The state of Medicine was far less advanced at the time.
To explain the Average Life Expectancy at the time WAS lower, maybe 35 years or so, but this is deceptive at first glance. A high infant mortality rate heavily skews this number. When 800 babies out of 1000 die before age 5, the average plummets. If you discount childhood deaths, an able bodied male that reaches adulthood (20+) of the early 1800's would live to be between 60 and 80 years old, some outliers reaching 90. (Women had the same issue with childhood deaths AND dying in childbirth, but still outlive men by 5 years on average).
Valjean, who in later life is a mayor, slightly well off, would be an old man in death. Compare him to the American Founding Fathers, same time period (Colonial America to Industrial Revolution), died as old men.
Thomas Jefferson 83, John Adams 90, George Wythe was 80, Paul Revere was 83, Ben Franklin was 84. Only George Washington died a young 67, from blood loss, not old age complications.
Given this, he died a bit younger than normal, baring accident/murder or medical illness. Having not been able to see Cosette anymore, he lost his will live, and that's very important. Ask anyone in a medical field, and they will tell you, someone fighting to live has a notably higher chance of surviving than those that don't, like the placebo effect.