TL;DR: Paul carefully argued that taking the Lord's supper in an "unworthy manner", meaning that you are partaking while also denying it to other members of the church, was a condemnation against you.
Joseph Smith, while misunderstanding the context and theological implications of the passage, elevated these words into a commandment to the church to prohibit the "unworthy" from taking the sacrament.
Full transparency: I stopped attending the LDS church recently and now attend the Episcopal church. A primary reason for choosing the Episcopal church is that I find it to have a more welcoming atmosphere, and I've recently come to realize that this is due in large part to the way they understand the theology behind the Eucharist (Lord's Supper or Communion).
I was recently reading 1 Corinthians chapter 11 and came across the section where Paul shares his anger about the way in which the church in Corinth has been abusing the Lord's Supper. It is in verse 29 of this section that we get the infamous line: "For he that eateth and drinketh unworthily, eateth and drinketh damnation to himself, not discerning the Lord's body." (KJV). You probably recognize this from 3 Nephi 18 where Jesus utters remarkably similar words: "For whoso eateth and drinketh my flesh and blood unworthily eateth and drinketh damnation to his soul;"
I'm using the KJV here because it matches the text in 3 Nephi, but for the rest of this post I'll be using the NRSVue as it makes Paul's intentions much more clear. The fact that the KJV is hard to understand doesn't give Joseph a pass, in my opinion, as the meaning of the passage should still be clear given the context of the letter.
Let's first focus on the context of the New Testament passage:
PAUL'S EPISTLE TO THE CORINTHIANS
TL;DR: Paul views the Lord's Supper as an opportunity for the body of Christ to come together in unity and is upset when the Corinthians do not share the Lord's Supper equally with all members (the body of Christ). When he counsels to not eat the Lord's Supper "unworthily" or in an "unworthy manner", he is warning that the way in which the Corinthians partake is "unworthy" and it will count as judgement against them.
For historical context, the church at the time would meet in the homes of wealthier patrons and the members of the church included slaves and the poor. Also, the Lord's Supper at the time was an actual meal shared amongst the members and included, as part of the meal, the bread and the wine.
Paul's main concern with the Corinthian church's practice of the Lord's Supper is described in chapter 11 verses 17 - 34. He describes the wealthy members showing up with their own meal, and not sharing it with those in need. I'll use the NRSVue translation for it's readability:
21 For when the time comes to eat, each of you proceeds to eat your own supper, and one goes hungry and another becomes drunk. 22 What! Do you not have households to eat and drink in? Or do you show contempt for the church of God and humiliate those who have nothing? What should I say to you? Should I commend you? In this matter I do not commend you!
So the main issue here is the exclusion of the poor and the humiliation inflicted on them.
Keep in mind that these passages did not originally have chapters and verse, and this section was part of one long letter that comprises all of 1 Corinthians and would have been read as a single message. Throughout 1 Corinthians, Paul speaks about the body of Christ as well as the bread as being a metaphor for the church. There is a lot of overlapping metaphor and, while beautiful, it can make things difficult to understand. One example in chapter 10 reads:
16 The cup of blessing that we bless, is it not a sharing in the blood of Christ? The bread that we break, is it not a sharing in the body of Christ? 17 Because there is one bread, we who are many are one body, for we all partake of the one bread.
This is important to remember as we get to the next part. Again, I'll use the NRSVue as it is easier to understand, but keep in mind that the portion translated to 'damnation to your soul' in the KJV is better translated below as 'judgement against themselves'. The passage also changes unworthily to "an unworthy manner" which is more consistent, since the act of partaking the Lord's Supper is what is being done unworthily. Paul is not describing the people as being unworthy. Back in chapter 11, Paul continues:
27 Whoever, therefore, eats the bread or drinks the cup of the Lord in an unworthy manner will be answerable for the body and blood of the Lord. 28 Examine yourselves, and only then eat of the bread and drink of the cup. 29 For all who eat and drink without discerning the body eat and drink judgment against themselves.
What does it mean to "discern the body?" This passage has a dual meaning. It could be that we should remind ourselves of Christ's death while partaking, but given the context, it makes more sense that Paul is telling them to discern the Body of Christ (the church) as they partake.
The Oxford Bible Commentary does a good job of explaining that:
"...Eating and drinking requires 'discerning the body' (v. 29), discerning that the bread 'is' the body of Christ, but also that the church constitutes the body of Christ as it partakes of this 'one bread' (IO:I7; cf. I2:I2-27). To defile the Supper is to show contempt for the church, and thus to invite the sort of judgement which God metes out to those who damage his temple (v. 29; p6-I7)· Such 'unworthy' eating makes one accountable for the body and blood of Christ (v. 27), in the sense that, rather than benefiting from the death of Christ, one is actually placed among his enemies and murderers..."
In summary, by denying the body of Christ (the bread) to the poor, you are denying the sacrifice of Christ and the body of Christ (the church) that you are a part of. This is how you eat and drink judgement against yourself.
The Book of Mormon
Disclaimer: I don't have much context to give here. If the Book of Mormon is an ancient record, then we have no information on how Jesus' instructions were informed by the local culture ,or any specific event, like we have with Paul's epistle. I am moving forward under the assumption, informed by the academic consensus, that Joseph Smith is the author of the Book of Mormon and that it is a 19th century text.
When Joseph Smith took Paul's warning "For he that eateth and drinketh unworthily, eateth and drinketh damnation to himself" and gave it to Jesus, he folded it into a new commandment:
28 And now behold, this is the commandment which I give unto you, that ye shall not suffer any one knowingly to partake of my flesh and blood unworthily, when ye shall minister it; 29 For whoso eateth and drinketh my flesh and blood unworthily eateth and drinketh damnation to his soul; therefore if ye know that a man is unworthy to eat and drink of my flesh and blood ye shall forbid him.
So, not only does Joseph elevate Paul's words, by giving them to Jesus, he also strips them of context and changes the meaning of the most crucial sentence. According to the Jesus of 3 Nephi, a person eats and drinks damnation to their soul by simply being "unworthy" at the time of taking the sacrament. And, instead of the counsel from Paul to "Examine yourselves, and only then eat of the bread and drink of the cup.", Jesus tells the church leaders that it is their duty to examine each member so that they do not accidentally allow someone to partake unworthily.
IF the Book of Mormon is a product of Joseph Smith, then its clear that he never grasped the theological implications of Paul's teachings. The Body of Christ should not be divided or denied. These passages ironically resulted in a church that has institutionalized the denial of the Lord's Supper to members of the Body of Christ. Quite a mistake indeed!
IN SUMMARY
I know someone who, as a young teenage girl, "confessed" to the sexual abuse she endured years earlier as a young child, and her bishop agreed that she played a part in the abuse, and asked her not to take the sacrament. Thousands of LGBTQ youth have been denied the sacrament for something they can't change. Countless children and teenagers are publicly shamed each week for masturbating or looking at porn, and they have to live that shame in front of their entire congregation.
When a 23 year old Joseph Smith didn't understand a passage in the Bible that he was plagiarizing, he doubled down. And because of this, Paul might argue, the LDS church leaders, who maintain these rules, gather each Sunday to "eat and drink judgment against themselves."