Short Answer: Paul was not in any way endorsing their action. On the contrary, Paul was bringing this up as evidence of their absurdity. The Corinthians were denying that the dead would be raised... but then they were turning around and getting baptized for them! His point is that they are being ridiculous.
First, Paul addresses the heresy head-on:
Now if Christ is preached, that He has been raised from the dead, how do some among you say that there is no resurrection of the dead?
Paul goes on to explain the sober implications of their heresy:
But if there is no resurrection of the dead, not even Christ has been raised; and if Christ has not been raised, then our preaching is vain, your faith also is vain. Moreover we are even found to be false witnesses of God . . . if Christ has not been raised, your faith is worthless; you are still in your sins. Then those also who have fallen asleep in Christ have perished. If we have hoped in Christ in this life only, we are of all men most to be pitied.
...in other words, this is a pretty serious claim to be making, and has pretty serious implications! Paul proceeds to set them straight in the truth:
But now Christ has been raised from the dead, the first fruits of those who are asleep. For since by a man came death, by a man also came the resurrection of the dead. . . .
After a brief excursus on the resurrection, Paul returns to their heresy -- this time to highlight its absurdity:
Otherwise, what will those do who are baptized for the dead? If the dead are not raised at all, why then are they baptized for them? Why are we also in danger every hour? I affirm, brethren, by the boasting in you which I have in Christ Jesus our Lord, I die daily. If from human motives I fought with wild beasts at Ephesus, what does it profit me? If the dead are not raised, let us eat and drink, for tomorrow we die.
Paul mentions two reasons why it is absurd to think that the dead are not raised. (We'll return to this in a moment.) Then he concludes with this:
Do not be deceived: “Bad company corrupts good morals.” Become sober-minded as you ought, and stop sinning; for some have no knowledge of God. I speak this to your shame.
Paul's conclusion is a shameful rebuke of the sinfulness and deception of this heresy.
The function of the paragraph
Paul poses two rhetorical questions in verses 29-32:
(A) If the dead are not raised, why are people being baptized for them?!
(B) If the dead are not raised, why would I be risking my life every day to preach the gospel?! I'd be much better off enjoying my life!
The purpose of both is the same: to show how absurd their heresy was. He had already covered the implications of the heresy, and had already finished providing a doctrinal refutation of it. This is neither. This is the "icing on the cake" of his argument. This is his way of saying "you are being ridiculous!"
The interpretation of the verse
For reference, here is verse 29 again:
Otherwise, what will those do who are baptized for the dead? If the dead are not raised at all, why then are they baptized for them?
First, notice that Paul is describing people who are being baptized for the dead. Given the context of the passage, it is hard to interpret "the dead" any other way than as people who are actually, literally, physically dead.
Second, notice who was being baptized for these dead people. Paul does not identify himself with that group. He says "they" are baptized for the dead; he is using "those" people's practice as evidence that the Corinthian heresy was absurd.
So to rephrase Paul's question in clearer English: If those who are dead are not going to be raised, then why are people getting baptized for them?! (If there was ever a time to recognize sarcasm in the Biblical text, this is it.)
Interpretation of the practice
By this point it should be clear that Group A was being baptized on behalf of physically dead Group B, and this somehow highlighted how ridiculous the Corinthian heresy was that the dead are not raised. Logically there seem to be two possibilities: either
(A) there was a legitimate practice of being baptized on behalf of dead people, which the Corinthian heresy jeopardized, or
(B) the Corinthians were being absurd in that they were saying the dead are not raised, but then turning around and getting baptized for them!
If it was (A) we would expect this argument to be located in the "implications" section of the passage, but it is not; It is located in the "look how absurd you're being" section of the passage, so interpretation (B) is more likely. This choice is further supported by the fact that there is zero evidence from elsewhere in Scripture that one person can be baptized on behalf of another (dead!) person -- in fact, this contradicts a number of other passages about each person being responsible for their own decisions, judgment coming immediately after death, etc.
So, in conclusion, it would seem that this practice entailed one person being baptized on behalf of another dead person under the false impression that this would have some effect on them in the resurrection, and that the absurdity lay in the fact that those who were performing this practice were turning around and claiming that the dead are not raised at all!
Reflection on the text
Thus, the structure of verses 29-32 takes the following form:
(A) If the dead are not raised, then why are you doing the ridiculous things you're doing? And,
(B) If the dead are not raised, then why would I be doing the (seemingly) ridiculous things that I'm doing?
This structure makes good sense in light of the flow of the passage, which is a nice check for this interpretation.