Here are two very peculiar verses from the bible:
Do not answer fools according to their folly,
or you will be a fool yourself.
Answer fools according to their folly,
or they will be wise in their own eyes (Prov 26.4-5).
Sometimes you hear people put this forth as an example of a contradiction in the bible, and of course those who suggest it is one will oftentimes take this as an example of why the bible is not the inspired word of God. If the bible has contradictions, then it can't come from God; it can't be describing reality, after all, since there are no contradictions.
Persons who reason in this way -- at least with regards to this present example -- are strange, indeed; it is as if they have never been at a loss whether to do a thing or no! Haven't we all had experiences where we had adequate reason to do a thing, and also not to do it? Haven't we all had times where the only solution seemed to be to flip a coin and assume the risks associated with whatever course of action we choose?
That is how I understand these two verses. There are reasons to answer fools according to their folly, and there are reasons not do it. Wisdom is recognizing the ambiguity of this situation and trying to make a reasonable judgment in every case.
You might answer a fool according to his folly so that he doesn't go through life convinced that he is right when he's actually wrong. We know persons like this: persons who not only are wrong, but don't know that they're wrong; they are actually convinced they're right, and perhaps they try to convince others of their errors. Persons like these can't go on uncontested ad infinitum, surely! They have to be answered according to their folly, so they don't think themselves so wise and so knowledgeable.
On the other hand, perhaps you have experienced a debate or discussion with a foolish person and seen that it quickly goes nowhere. The other person may not know how to reason, may not argue in bad faith, may simply say things to annoy you and anger you. Then you quickly get dragged down to his level because you lose your cool and try to respond in kind. In this way arguing with a fool is quite an unpleasant and fruitless exercise; arguing presupposes goodwill and the capacity to follow the argument, which many fools simply lack altogether. This is even worse when the fool pretends to be a philosopher and to have an enlightened opinion. Like Epictetus says somewhere, "God save me from people who know a little philosophy -- no one is harder to reach,"
So there are reasons to do it and reasons not to do it. Being wise entails being able to discern when it is appropriate and when it isn't. It is not a contradiction in the bible to advise a thing and advise against it, because human agency is very complex, and the world we live in is one of grey, not black and white.