He gives us an illustration of a person who works with great diligence, fortitude and wisdom and so builds up his wealth. Yet, inevitably the person dies and another, who has not struggled to build this wealth, then gets to spend it and enjoy the fruits of his labor. In the quest to find meaning in work, the Preacher finds life unfair. The question implies a negative response. In v22 the Preacher answered the question by implication, but now he explains why work is not worth the effort.
Work just goes on and on.
The whole mess of it is meaningless. In our day, just as in the Preacher's day, popular wisdom teaches that those who work hard in their lives will prosper. In developed countries this tends to be true. For a person who simply works to live, their 9 to 5 can actually be both rewarding and fulfilling. They come home and don't think about work and have a ball on the weekend.