Paul is concerned for the quality of the Corinthians' faith and their daily living. After all, we have a stark example from Israel's history that it matters how we live and worship. What should be the standard for living out our faith?
Beginning in New Testament times, a comparison has often been drawn between the Israelite sojourners in the wilderness, and the Christian pilgrimage of sanctification. Paul is one of the first to describe the spiritual similarities between engaging in rowdiness, testing, and complaining - then and now. His challenge to the Corinthian church is to avoid the mistakes of the ancient Israelites and instead pursue a higher calling that will please God.
Paul specifically applies this teaching to the matter of idolatry. He clearly commands the Christians not to engage in pagan worship (vs. 14). Thus, we may not join in eating what has been sacrificed to idols (or demons). Christ and idols are mutually exclusive - we cannot share in both the cup of Christ and the cup of demons.
Yet there is the corollary issue - what of carcasses that had been sacrificed to an idol but then brought out to the meat market to be sold? Is it polluted? This was a live issue for the Corinthians - in the marketplace of that era, it was common to find meat that had been slaughtered in the pagan temples for sacrifice. Because Paul knows that serving as an idol sacrifice doesn't really affect the meat itself, he counsels that the Corinthians shouldn't be troubled about it. "Eat whatever is sold in the meat market" (vs. 25) and "eat whatever is set before you" (vs. 27).
However, Paul also realizes that other believers, whose consciences are weak, could be troubled and led astray by seeing their brothers and sisters eating meat that they know has been sacrificed. Therefore, Paul gives the corresponding word that, if it becomes known that the food is spiritually "tainted," Christians should refrain from eating, lest they give offense to their spiritual brothers and sisters. Otherwise, a policy of "don't ask, don't tell" should be good enough when it comes to what we eat.
To sum up: Always be considerate of others - whatever you do, do it for the glory of God! (vs. 31)