The sages wished to pronounce Coheleth apocryphal, because its statements are contradictory. And why have they not declared it apocryphal? Because it begins with words of the law, and ends with words of the law, for it opens with the words “What advantage has man in all his labor wherewith he labors under the sun?” &c., &c.—Sabbat. 30 b.
So also in the Midrash: “The sages wished to pronounce Coheleth apocryphal,” &c., &c.—Vayyikra rabba 161 b.