Good question. The two texts certainly might appear to contradict one another, but we should remember that the same author wrote both statements — that in 14:27 and that in 18:18. Let me first cite the comments of Matthew Henry (strangely, the Bible Knowledge Commentary passed over this matter), and then comments from my sermon on 2 Samuel 18 from the BSF Website:
That his family began to be built up. It is probable that it was a good while before he had a child; and then it was that, despairing of having one, he set up that pillar which is mentioned ch. 18:18, to bear up his name; but afterwards he had three sons and one daughter, v. 27. Or perhaps these sons, while he was hatching his rebellion, were all cut off by the righteous hand of God, and thereupon he set up that monument.
The text adds a kind of epitaph to the account of Absalom’s death. The author informs us that at one time Absalom had no sons, and fearing that he would be forgotten, built a pillar for himself in the valley of the kings. By this, he thought, he would preserve his name. As it turned out, Absalom did have sons, but in his desire to possess his father’s throne, he was able to be king but for a few days, and now he will be remembered as the traitor who died, hanging from a tree, the most ignoble death of all. His pillar in the valley of the kings would never erase the memory of his folly and death.
I might add this additional comment. In 2 Samuel 14, the context is Absolom’s flight to Talmai from Israel and David, his exile there, and then his return to Israel. We are told of the birth of Absolom’s children after his return from exile. I would guess that while in exile Absolom began to fear that he would spend the rest of his years away from Israel, and began to despair of returning, and raising a family. This would seem to be the time when he would most likely have built a monument to himself.