A useful way to think about poetry is that poems make observations about the human experience. "O Captain! My Captain!" was inspired by the death of Abraham Lincoln, a man Walt Whitman greatly admired; in fact, the poem is an elegy, a formal poem of mourning.
Because Whitman does not name Lincoln as the subject of the poem, it can be read as a work that captures the emotions surrounding the death of a greatly admired or respected leader. The speaker exhorts his captain to rise from the deck where he has fallen dead; he wants the captain to be able to enjoy the rewards of the successful journey they took together and join the people who are gathered to celebrate. He implores the captain to rise and receive the adulation of the crowds gathered in his honor. At the end of the poem, the speaker sorrowfully observes that his captain cannot answer and has not lived to share in the triumph.
Whitman's controlling idea is the tragedy inherent in the death of a leader who doesn't survive to witness his legacy. Though in this case he means, particularly, the president who has led the reunification of the United States in the Civil War, the poem's lament is generally for anyone who does not live to see the fruits of his or her labor.