once upon a midnight, dreary

here the author begins the expression with a familiar phrase, "once upon a time", but changes the phrase midway, replacing the word "time" with "midnight". the disjointness immediately produces multiple impacts in a reader or hearer.

in present day, we don't often say "once upon a midnight", but we do say "once upon a time" and this stimulates the setting of a scene, the imagination of some environment from long ago where a pleasant story might happen.
we also say similar things, like "one day" or "once when i was getting pickles".