Norman Denny has this to say in the introduction to his translation of Les Misérables:
Hugo [...] had little or no regard for the discipline of
novel-writing. He was wholly unrestrained and unsparing of his reader.
He had to say everything and more than everything; he was incapable of
leaving anything out. [...]
One reason for [so many digressions] is that it was written over a period of nearly
twenty years. A first unfinished novel entitled Misères was written
during the three years from 1845 to 1848; it was then put aside for
twelve years, to be completed in 1860-62 as Les Misérables.
Hugo, as he tells us, had tramped over the battlefield, presumably
when he was living in Brussels in 1853; he had studied maps and
army-lists and such professional records as were available to him, and
out of this he concocted his own elaborate and poeticized layman's
version of an event [...]. This is the largest of the digressions, and
it is reasonable to assume that the bulk of it was written long before
Hugo returned to his novel.
Hugo's publisher, Lacroix, feeling that this would be trying the
reader's patience altogether too high, urged him to take it out; but
Hugo refused, as it seems for purely personal reasons: his cousin
Marie, to whom he was attached, had taken the veil in 1848.
Denny then proceeds to drop some of these digressions to appendices in his translation, making his Les Misérables a far more pleasant prospect.