As I understand it, he was backsidden for all but the last two verses where he started coming to his senses.
"
13 Now all has been heard;
here is the conclusion of the matter:
Fear God and keep his commandments,
for this is the duty of all mankind.
14 For God will bring every deed into judgment,
including every hidden thing,
whether it is good or evil. "
You are
gravely mistaken.
All scripture is given by the Holy Ghost (2 Timothy 3:16-17; 2 Peter 1:21), and the person speaking through the Holy Spirit is 'Jesus'. The book of Ecclesiastes begins with:
Ecclesiastes 1:1 - The words of the Preacher, the son of David, king in Jerusalem.
Ecclesiastes 1:12 - I the Preacher was king over Israel in Jerusalem.
The real ""Preacher, the son of David", who is truly the "king over Israel in Jerusalem" is Jesus speaking through the Holy Ghost by Solomon (Son of David).
So, Ecclesiastes is not Solomon's backslidden state, but his re-converted state, after having experienced all those things, and wrote to tell us of those things experienced looking for all "wisdom" of Heavenly and Earthly.
The conclusion gives this away, as given by the "one shepherd", Jesus Christ, Lord of the congregation/church (a master of assembly):
Ecclesiastes 12:9 - And moreover, because
the preacher was wise, he still taught the people knowledge; yea, he gave good heed, and sought out,
and set in order many proverbs.
Ecclesiastes 12:10 -
The preacher sought to find out acceptable words: and
that which was written was upright,
even words of truth.
Ecclesiastes 12:11 -
The words of the wise are as goads, and as nails fastened
by the masters of assemblies,
which are
given from one shepherd.
Ecclesiastes 12:12 - And further,
by these, my son,
be admonished: of making many books
there is no end; and much study
is a weariness of the flesh.
Ecclesiastes 12:13 - Let us
hear the conclusion of the whole matter: Fear God, and keep his commandments: for this
is the whole
duty of man.
Ecclesiastes 12:14 - For God shall bring every work into judgment, with every secret thing, whether
it be good, or whether
it be evil.
Thus when Solomon (by the Holy Ghost), in Ecclesiastes 9:5,6,10, &c is writing, it is not in a backslidden state, or melancholy. It is written as "words of truth", "words of the wise" (Jesus is truth and wisdom), even "acceptable words", "upright" (without sin) words to be "admonished by" (to learn from about the things of nature around us), for the "preacher" is teaching true "knowledge" of the events of earth.
Ecclesiastes 9:3-10 reads:
3 This is an evil among all things that are done under the sun, that there is one event unto all: yea, also the heart of the sons of men is full of evil, and madness is in their heart while they live, and after that they go to the dead.
4 For to him that is joined to all the living there is hope: for a living dog is better than a dead lion.
5 For the living know that they shall die: but the dead know not any thing, neither have they any more a reward; for the memory of them is forgotten.
6 Also their love, and their hatred, and their envy, is now perished; neither have they any more a portion for ever in any thing that is done under the sun.
7 Go thy way, eat thy bread with joy, and drink thy wine with a merry heart; for God now accepteth thy works.
8 Let thy garments be always white; and let thy head lack no ointment.
9 Live joyfully with the wife whom thou lovest all the days of the life of thy vanity, which he hath given thee under the sun, all the days of thy vanity: for that is thy portion in this life, and in thy labour which thou takest under the sun.
10 Whatsoever thy hand findeth to do, do it with thy might; for there is no work, nor device, nor knowledge, nor wisdom, in the grave, whither thou goest.
Notice, as you said, "under the sun", which means it is not speaking about Heavenly things here (and thus no immortal souls peaking down from heaven above are in these verses, so the text even works against your own position).
Vs. 3 states, "while they live, and after that they (the living when they die) go to the dead (ie buried with their fathers)
Vs. 4 states that "hope" only exists to "all the living", not to those who are dead, for he says that even a "living dog" is better than "a dead (not living) lion".
Vs. 5 states, "the living know", but "the dead know nothing"
Vs. 6 states "also their love", "hatred", "envy" is "now" (while dead, presently) "perished" (gone), and they which are dead do not have "anything" more to do with "any thing that is done under the sun" (on earth), because they are dead and buried and can no more act (Vs 10).
Vs. 7-9 refer to events that only he living can participate in, such as "eat", "drink", "works",, "labour", wearing "garments" (clothes), having a "head" to be anointed with "oil", and to be married to a "wife" in their "life" "under the sun". As we know, Jesus said that those who obtain the Heavenly kingdom never marry, nor are given in marriage.
Vs. 10 states that to do everything while alive, for when a person dies, they are "in the grave" (not heaven), and can no longer "work", have no "device", nor "knowledge", nor "wisdom". The passage does not say the 'body' goes to the grave, the Hebrew and English are clear, it is "thou" (the person themselves) that when they die, go "in the grave".
Ecclesiastes 12:5-7 reads:
5 Also when they shall be afraid of that which is high, and fears shall be in the way, and the almond tree shall flourish, and the grasshopper shall be a burden, and desire shall fail: because man goeth to his long home, and the mourners go about the streets:
6 Or ever the silver cord be loosed, or the golden bowl be broken, or the pitcher be broken at the fountain, or the wheel broken at the cistern.
7 Then shall the dust return to the earth as it was: and the spirit shall return unto God who gave it.
So Solomon (by the Holy Ghost, so really Jesus), states:
Vs. 5 states that when a person dies they go to "their long home" (grave), their "desire" ceases, and those who live "mourn" over them.
Vs. 6 states the person becomes non functional, as a "bowl" "broken", or "cord" "loosed" (cut)
Vs. 7 states that the dust (which man was made of in the beginning; Genesis 2:7, a dead soul, until the breath of life of God was breathed into the nostrils of the dust) returns to the "earth" (not goes anywhere else), and the "spirit" (is not an immortal soul of a person, but is the breath of the living God, being His breath, His spirit, which animated the dust, gave consciousness and life to it, and when taken back (Job 34:14-15), simply returns to Himself as it began in Heaven with Himself.
Notice, that if as persons say that an immortal soul/spirit exists of the person, then even the wicked returns to God in Heaven, for the passages make no such distinction. It just states that the "spirit returns to God who gave it". If it is not simply God's animated breath, persons who believe in immortal soul/spirit theology have a serious problem, that even the occult understand and utilize, teaching that even Hitler, Pol Pot, etc are in Heaven by twisting (wresting) those scriptures.
Please think more carefully about Ecclesiastes. Thank you.