This passage is a warning and a promise. It fits in the context because Paul is warning the Corinthian church about some of the same issues that the Israelites struggled with during their wilderness wanderings.
The Israelites were “baptized into Moses” like we are baptized into Christ. Moses was their leader and, in a sense, savior. Under his leadership they came out of Egypt, crossed the Red Sea, received manna, and got water out of a rock! Incidentally, some rabbi’s thought that the rock followed them around in their wanderings and continued to provide water. Paul indicates here that the rock symbolized Christ, and that they were nurtured by Him and didn’t even understand it! Anyway, after all the advantages and care that the Israelites received, many still rebelled and were punished (10:5). Paul warns the Corinthians not to be like the Israelites (10:6). They engaged in idolatry (Exodus 32:1-6), immorality (Numbers 25:1-9), and testing (Numbers 21:4-9). In applying the next few verses to us in our day and age, we understand that all these failures were written down as examples for us so that we can do better (10:12). We are not alone, and we are not unique. Others have experienced what we are experiencing. We can learn from them, even as we understand that God Himself is our greatest help. He has promised that he will help us through trials by providing a way out so that we can remain faithful (10:13)!
1 Corinthians 10:13 is both one of the most exciting and terrifying verses in the Bible. Exciting because it assures us that God is with us no matter what we face, and will give us the patience, endurance, and strength to resist sin and make it through. Terrifying because, if we fail, it’s entirely our own fault and shows us that our relationship with God was not where it should have been.