The Teacher does not distinguish between humans who believe in God or the godless. ALL humans will die and their bodies go into the ground where "the dust returns to the ground it came from."
Likewise, all animals will die and go into the ground.
The difference between what happens to humans and to animals after physical death lies in the fact that only humans are made in the image of God (Genesis 1:2). Animals are not.
Ecclesiastes 3:11 informs us that God has set eternity in the hearts of men. God has not set eternity in the hearts of animals.
The Teacher has this to say about it in Ecclesiastes 3:19-20:
Man's fate is like that of the animals; the same fate awaits them both: As one dies, so dies the other. All have the same breath; man has no advantage over the animal. Everything is meaningless. All got to the same place; all come from dust, and to dust all return.
This refers to the body and the breath of life. But what about the spirit of man?
Who knows if the spirit of man rises upward and if the spirit of the animal goes down into the earth? (Ecclesiastes 3:21)
The Conclusion of the Matter is that
God will bring every deed into judgment, including every hidden thing, whether it is good or evil. (Ecclesiastes 12:14)
No mention anywhere of animals continuing to exist after physical death. No mention of God judging the actions of animals to discover if they were good or evil. No mention of a resurrection for animals anywhere in the Bible. That is because animals are not made in God's image (Genesis 1:2).
The last book in the Bible describes how God will judge humanity "according to what they had done" (Revelation 20:11-15). There is to be a resurrection of humanity - of all who have lived and died, both the righteous and the unrighteous, but there is no resurrection of animals.
The body of animals returns to the dust but they do not have a soul that returns to God.