The overarching theme is the death of Abraham Lincoln. His death heralded not only the end of the Civil War (Whitman's original motivation for writing "Song of Myself" was, according to Whitman scholar Ed Folsom, an attempt to use poetry to keep the nation together) but also the end of a great presidency. The passage of the Fourteenth and Fifteenth Amendments attempted to make the nation more equal.
Each stanza addresses a more specific theme in relation to this general one. In the first line of the first stanza, the narrator speaks of a "fearful trip [that is] done." This is a metaphor for the Civil War. The speaker continues: "The ship has weather’d every rack, the prize we sought is won, / The port is near, the bells I hear, the people all exulting...." The "ship" could be the nation, which Whitman envisions as a moving vessel that has "weather'd" every storm, or "rack." By using the pronoun "we," the narrator establishes an allegiance with the Union, which "won" the prize—both the war and the right to keep the country together. "The port" is the end of the war, at which everyone exults. Bells signal jubilation, which abruptly ends at the sight of "bleeding drops of red"—an allusion to the shot that killed Lincoln.
The second stanza is the nation's period of mourning and includes direct references to aspects of Lincoln's funeral ("[f]or you bouquets and ribbon'd wreaths," "the swaying mass"). The narrator, like most of the nation, cannot imagine a nation without the president: "It is some dream that on the deck, / You’ve fallen cold and dead."
The third stanza is about reckoning with the reality of Lincoln's demise: "My Captain does not answer, his lips are pale and still, / My father does not feel my arm, he has no pulse nor will...." Notice here that Lincoln is not only the nation's leader, or "Captain," but also a paternal figure, guiding the nation morally. He is responsible for having birthed a new nation that will no longer sanction slavery.
The nation has been made safe, and the war has ended ("The ship is anchor’d safe and sound, its voyage closed and done, / From fearful trip the victor ship comes in with object won..."). However, the narrator remains in mourning for the loss of a great man: "But I with mournful tread, / Walk the deck my Captain lies, / Fallen cold and dead."