If we keep reading in 1 Corinthians 10 we see that there is no contradiction. Paul is stating that we are free to eat whatever is put before us, unless there is an issue of conscience, ie the conscience of the weaker brother.
18 Behold Israel after the flesh: are not they which eat of the
sacrifices partakers of the altar?
Here is a key premise: Paul is saying that the Jews which are eating OT sacrifices without faith in Christ (ie, after the flesh – by works not faith) they themselves are partakers of the OT sacrifice system. That is, they are still under the Old Covenant and still partakers of attempting to attain righteousness via the Old Covenant of animal sacrifices. In effect, they give evidence they have not yet move from death to life, OT to NT.
He then applies this same principal to the Gentiles.
19 What say I then? that the idol is any thing, or that which is
offered in sacrifice to idols is any thing? 20 But I say, that the
things which the Gentiles sacrifice, they sacrifice to devils, and not
to God: and I would not that ye should have fellowship with devils. 21
Ye cannot drink the cup of the Lord, and the cup of devils: ye cannot
be partakers of the Lord's table, and of the table of devils.
So, here Paul then applies the same principal to Gentiles. He says that the Gentiles who are still weak in faith offer sacrifice to idols are still in effect partakers of idolatry. Even thought the mature believer understands that idols are nothing, the Gentile still does and if the mature believe partakes in eating meat sacrificed to idols (when everyone understands what is happening – see below) then the mature believe becomes a partaker in the idolatry due to the conscience of the weaker brother. Keep reading.
22 Do we provoke the Lord to jealousy? are we stronger than he? 23 All
things are lawful for me, but all things are not expedient: all things
are lawful for me, but all things edify not. 24 Let no man seek his
own, but every man another's wealth.
Paul says that to the mature believer, all things are lawful but not all things edify; this is that case with eating meat sacrificed to idols when both parties understand the significance. Keep reading.
25 Whatsoever is sold in the shambles, that eat, asking no question
for conscience sake: 26 For the earth is the Lord's, and the fulness
thereof. 27 If any of them that believe not bid you to a feast, and ye
be disposed to go; whatsoever is set before you, eat, asking no
question for conscience sake. 28 But if any man say unto you, this is
offered in sacrifice unto idols, eat not for his sake that shewed it,
and for conscience sake: for the earth is the Lord's, and the fulness
thereof: 29 Conscience, I say, not thine own, but of the other: for
why is my liberty judged of another man's conscience? 30 For if I by
grace be a partaker, why am I evil spoken of for that for which I give
thanks? 31 Whether therefore ye eat, or drink, or whatsoever ye do, do
all to the glory of God. 32 Give none offence, neither to the Jews,
nor to the Gentiles, nor to the church of God: 33 Even as I please all
men in all things, not seeking mine own profit, but the profit of
many, that they may be saved.
So here Paul lays out the premise. He says that if you go to a dinner and they set before you meat sacrificed to idols and no one says anything about it, then you are free to eat, since we all know that there is no other god but the Lord.
However, Paul says, if they tell you that this meat is sacrificed to idols (making sure you understand the significance) then you must refrain because of conscience sake, ie the conscience of your weaker brother. For if you would eat, then in-effect, you are sanctioning the practice and affirming that the weaker brother’s idolatry is correct. This would in effect make Christ a party to the idolatry hence the reference to fellowship with devils in V20-21.