The best way to learn history is not always in a textbook. (That's probably the worst way, really, but more on that elsewhere.) While learning history through novels can be taken too far (it is fiction after all), there's much to be said for getting a feel for the Civil War through books like The Red Badge of Courage or Across Five Aprils, or learning about the deep rifts between Saxons and Normans in Medieval England through Scott's Ivanhoe.
A well-researched historical novel imparts something no list of names and dates can—a picture of life among a particular people at a particular time, the way they thought, the way they ate, who they admired, how they traveled. Sometimes readers are introduced to real historical figures and events from an intimate perspective, not the stale cardboard presentations common in schools.
There's plenty of nonsense available, of course, and just because the cover says a book takes place in Renaissance Italy or ancient Egypt doesn't mean it's a good book, or even that it's historical fiction in the true sense. A writer who simply transposes stories on different time periods isn't really saying anything about that time period, they're just trying to inflate sales with an appeal to the exotic and unfamiliar.
Such bogus historical fiction is really just fantasy. The good stuff is real and bright and dusty and loud, just like an old Roman city or a battle between Roundheads and Cavaliers. It reflects the religious sentiments of the characters as they would have been, such as in Lilli Thal's brilliant Medieval epic Mimus. It shows how one small action can lead to many much larger events, as happens frequently in C.S. Forester's Hornblower series.
Whether you're into the technical descriptions of battles found in Henty's boy-versus-the-world stories, or prefer the romance of The Scarlet Pimpernel, or like to break your heart over and over with books like Amos Fortune, Free Man, historical fiction is above all fiction of the present—not to be kept in the annals of the past, it shows us that the people of long ago (or not so long ago) are not so different than the people of today.