The ending of Ecclesiastes is a little confusing. The voice of an editor cuts in and suddenly says, "Well, you know, that's all well and good. But there's no point getting all caught up in this intellectual search for wisdom, when all you really need to know is that you should follow God's commandments and be aware that he'll bring everyone to judgment." It sort of undercuts Ecclesiastes's message, really.
The actual Ecclesiastes toys with the idea that God will judge everyone—but he keeps contradicting himself. It's like he's flip-flopping, never able to make up his mind about this, never sure whether he thinks that bad deeds go unpunished. Before the editor (or whoever) intrudes with his two-cents, Ecclesiastes ends the book by describing the inevitability of death, telling us to remember God and reminding us one more time that everything is vanity. He ends where he began.