The original sense of the expression may be tied to a Christianized association of the mythical Greek Fortunate Islands or Isles of the Blessed, said to lie in the extreme west of the Atlantic Ocean—toward the sunset. The Greek Mythology Link page for "Isles of the Blest, Elysium, White Isle" offers these notes (with quotations from Strabo):
The Islands of the Blest
The Islands of the Blest is a place where the virtuous dwell after death, retaining their faculties and enjoying a life free of care. This is probably the last abode of the righteous soul (and no reincarnation seems to affect those living in these islands).
According to some, the Islands of the Blest were by the western limits of Libya, that is, beyond the pillars of Hercules (Gibraltar) in the Atlantic Ocean, or as Strabo says:
"… even calling by name certain Isles of the Blest, which, as we know, are still now pointed out, not very far from the headlands of Maurusia that lie opposite to Gades (now Cádiz)." (Strabo, Geography 3.2.13).
Above all these islands were a place "untouched by sorrow", where a blessed life could be lived after death. They were thus associated or identified with Elysium (the Elysian Plain, also called Elysian Fields), which was "at the ends of the earth". According to Strabo, this expression refers to the West:
"For both the pure air and the gentle breezes of Zephyrus properly belong to this country, since the country is not only in the west but also warm; and the phrase 'at the ends of the earth' properly belongs to it, where Hades has been 'mythically placed,' as we say." (Strabo, Geography 3.2.13).
Encyclopedia.com has this brief entry for "Islands of the Blessed":
Islands of the Blessed (in classical mythology) a land, traditionally located near the place where the sun sets, to which the souls of the good were taken to enjoy a life of eternal bliss.
Sailing westward toward a setting sun and hoped-for admission to a blessed destination thus became a metaphor for the inescapable end of life and for the possibility of heaven and immortality.
That may help explain instances such as this one from Edwin Hood, "That Rest.---Aspects of Death," in Dark Sayings on a Harp; and Other Sermons on Some of the Dark Questions of Human Life (1865):
I think the difference between souls is greatly in this, the want and need of Sabbath occasions and Sabbath hours; we long during the week for the Sabbath, and then we look forward to the hour
"When the Master of Life shall call us / To the land of light and morning, / When our evening sun descending / We shall sail into the sunset, / Sail into the dusk of evening, / To the islands of the blessed, / To the kingdom of the Father, / To the land of the hereafter,
And enjoy that rest.
And likewise, from "Remarks of Augusta Cooper Bristol at the Spiritualist Convention Held at Lempster, N.H., Aug. 4th," in the [Toledo, Ohio] Index (September 16, 1871):
The Free Religionist appeals to science for the final answer to that question which the anxious heart of Humanity is forever asking—"Is the soul of man immortal?" And should universal Reason decide that Spiritualism yields no affirmation to this interrogation, then the very heart of Man can do no better than return to its old plaintive hymn of hope and faith, and sail into the sunset with all life's patient agony wrought into that song of death.
Even earlier is the closing scene from Henry Longfellow, The Song of Hiawatha (1855):
And the evening sun descending / Set the clouds on fire with redness / Burned the broad sky, like a prairie, / Left upon the level water / One long track and trail of splendor, / Down whose stream, as down a river, / Westward, westward Hiawatha / Sailed into the fiery sunset, / Sailed into the purple vapors, / Sailed into the dusk of evening.
...
Thus departed Hiawatha, / Hiawatha the Beloved, / In the glory of the sunset, / In the purple mists of evening, / To the regions of the home-wind, / Of the Northwest wind Keewaydin, / To the Islands of the Blessed, / To the Kingdom of Ponemah, / To the land of the Hereafter!
It seems fairly clear that Hood, a British cleric writing in England in 1865, was repackaging Longfellow's lines from ten years earlier, giving them a more explicitly religious cast and omitting the "purple vapors." In any event, it may well be that the adoption of the idiom "sailing into the sunset" in the United States is ultimately attributable to its occurrence in Longfellow's hugely popular poem.