(with regards to Ecclesasties 5:2)
Matthew Henry says......
Verses 1-3 Address thyself to the worship of
God, and take time to compose thyself for it. Keep thy thoughts from roving and wandering: keep thy affections from running out toward wrong objects. We should avoid vain repetitions; copious prayers are not here condemned, but those that are unmeaning. How often our wandering thoughts render attendance on Divine ordinances little better than the sacrifice of fools! Many words and hasty ones, used in prayer, show folly in the heart, low thoughts of God, and careless thoughts of our own souls.
I take this to mean we should keep our minds and hearts focused on God, and on our requests, and not ramble on about this and that in a helterskelter manner........or using "vain repetitions." Jesus also spoke against such....
I do not think this discounts what the Apostle Paul wrote in any way......
(with regards to 1 Thessalonians 5:17)
Matthew Henry wrote:
5:16-22 We are to rejoice in creature-comforts, as if we rejoiced not, and must not expect to live many years, and rejoice in them all; but if we do rejoice in God, we may do that evermore. A truly religious life is a life of constant joy. And we should rejoice more, if we prayed more. Prayer will help forward all lawful business, and every good work. If we pray without ceasing, we shall not want matter for thanksgiving in every thing. We shall see cause to give thanks for sparing and preventing, for common and uncommon, past and present, temporal and spiritual mercies. Not only for prosperous and pleasing, but also for afflicting providences, for chastisements and corrections; for God designs all for our good, though we at present see not how they tend to it. Quench not the Spirit. Christians are said to be baptized with the Holy Ghost and with fire. He worketh as fire, by enlightening, enlivening, and purifying the souls of men.
By reading vs. 17 in context, we see how Henry revealed an understanding of the Scriptures which is good and worthy of a believers considerations........
14) Now we exhort you, brethren, warn them that are unruly, comfort the feebleminded, support the weak, be patient toward all men.
15) See that none render evil for evil unto any man; but ever follow that which is good, both among yourselves, and to all men.
16) Rejoice evermore.
17) Pray without ceasing.
18) In every thing give thanks: for this is the will of God in Christ Jesus concerning you.
19) Quench not the Spirit.
20Despise not prophesyings.
21Prove all things; hold fast that which is good.
22Abstain from all appearance of evil.
23And the very God of peace sanctify you wholly; and I pray God your whole spirit and soul and body be preserved blameless unto the coming of our Lord Jesus Christ.
Both Scriptures asked about in the OP are the Inspired Word of God, and neither contradicts the other IMO.