Taken from Benson Commentary on 1 Cor 15:29 as displayed on Biblehub.com
I reproduce this explanation for those who are confused (which is just about everybody) with these words from the Apostle Paul to the Corinthian church. As the Apostle Peter noted some of the words of Paul in his writings to the churches are difficult to understand (2 Pe 3:16 – He writes the same way in all his letters, speaking in them of these matters. His letters contain some things that are hard to understand, which ignorant and unstable people distort, as they do the other Scriptures, to their own destruction.) Both Romans and the two Corinthian letters could be cited in this regard.
The Mormons have built an entire cult conducting baptisms for the dead relatives of their people (which is why the Mormons have the largest genealogy collection on the planet) and justify this practice mainly from this one verse.
But here we have three concise and brief explanations which I found helpful. Many other commentators could also be fruitfully consulted online at this and other sites.
Else what shall they do which are baptized for the dead, if the dead rise not at all? why are they then baptized for the dead? 1 Corinthians 15:29-30. Else, or otherwise, what shall they do — What will become of them? what shall they do to repair their loss, who are exposed to great sufferings in consequence of being baptized for the dead — That is, say some, “In token of their embracing the Christian faith in the room of the dead, who are just fallen in the cause of Christ, but are yet supported by a succession of new converts, who immediately offer themselves to fill up their places, as ranks of soldiers that advance to combat in the room of their companions, who have just been slain in their sight.” Others say, “In hope of blessings to be received after they are numbered with the dead.” Many other interpretations are given of this obscure and ambiguous phrase, υπερ των νεκρων, for the dead. But perhaps that of Dr. Macknight is the most probable, who supplies the words της αναστασεως, and reads the clause, who are baptized for the resurrection of the dead, or are immersed in sufferings, because of their believing in, and testifying the doctrine of the resurrection of the dead: for which interpretation he adduces solid reasons. If the dead rise not — If the doctrine I oppose be true, and the dead are not raised at all; why are they then baptized for the resurrection of the dead? And why stand we — The apostles; also in jeopardy — And are exposed to so much danger and suffering; every hour — In the service of a Master from whom, it is evident, we have no secular rewards to expect.