Those two passages agree if we read them within the larger context. I suggest you have taken Matthew 7:21-23 out of context, which distorts its meaning, then tried to read 1 Corinthians 12:3 in light of that. Obviously, that confuses the meaning. I will endeavor to put the Matthew passage back into context, and into the larger context of Jesus' teaching as recorded in the Gospels. Then I will show how this agrees with Paul's writing to the Corinthians.
Matthew 7:21-23
Matthew 7:21-23 is the second part of Jesus' parable about the Tree and Its Fruit. Jesus begins in V. 15 by saying, "Beware of false prophets." He goes on to say that people, i.e. prophets, can be known by their fruits the same way as trees can be known by their fruits. For example, he says, no one gathers grapes from thorn bushes or figs from thistles (V. 16). Good trees, he says, cannot bear bad fruit, nor vice versa.
I think all of us have enough life experience and understanding of biology and horticulture to realize that apples don't grow on thorn bushes, but that each kind of plant bears its own seed in its fruit. Likewise, some plants produce fruit good to eat while others produce poisonous fruit. Thorns and thistles, as most of us know, are prickly weeds that pierce the skin--not good.
Jesus compares the false prophets to the poisonous fruit, to prickly thistles and thorns that only hurt. Jesus also compares these false prophets to "ravening wolves in sheep's clothing," i.e. deceivers and/or traitors (V. 15), like the con-people and their scams we are all so familiar with. These false prophets will say "Lord, Lord, did we not do all these good deeds in your name?" V. 22.
Those are the people Jesus rejects. He is saying that they may have deceived the innocent and the gullible but they won't deceive him no matter how much they flatter him. That is what I understand him to mean when he says in Verse 21:
21 “Not everyone who says to Me, ‘Lord, Lord,’ will enter the
kingdom of heaven, but he who does the will of My Father who is in
heaven will enter.
Compare Matthew 25:31-46
The passage in Matthew 25:31-46 in which Jesus speaks about The Judgment agrees with the above explanation. At the judgment, Jesus says, all the nations will be gathered before him; he will divide them, with the sheep on his right and the goats on his left. The sheep are the good people who have done the will of his Father and are invited into the Kingdom and the goats are the bad people who have not done the will of God; they are told to "Depart from me!" The good people are surprised at their reward and ask, "What have we done to deserve this?" Jesus will list all the deeds of charity and reply:
‘Truly I say to you, to the extent that you did it to one of these
brothers of Mine, even the least of them, you did it to Me.’ V. 40.
The bad people will also be surprised at their reward and ask, "What did we do to deserve this?" Again, Jesus will reply with all the deeds of charity that they did NOT do and reply:
‘Truly I say to you, to the extent that you did not do it to one of
the least of these, you did not do it to Me.’ V. 45
In other words, when people fail to bring forth good fruits (as described above in Matt. 7), Jesus does not look upon them favourably. Pretending not to know what they did wrong, calling him Lord, Lord, will not get them anywhere at that point.
I think we have now established that in Matthew 7.21-23 Jesus is describing unrighteous or bad people, and clarifying that unlike some people he might name he will not buckle to flattery.
Correctly Acknowledging Jesus' Lordship
Jesus did not object to being called Lord when done so in sincerity. From John 13:13-14:
13 You call Me Teacher and Lord; and you are right, for so I am. 14 If
I then, the Lord and the Teacher, washed your feet, you also ought to
wash one another’s feet.
In other words, serving tired servants--even washing their weary filthy feet that had walked the sewers of the city--was the responsibility of a real Lord and Teacher (some translations say Master).
1 Corinthians 12:3
Then, to get even closer to the meaning of Paul's meaning in 1 Corinthians 12:3, there is Peter's Confession of Christ in Matthew 16:13-20.
16 Simon Peter answered, “You are the Christ, the Son of
the living God.” 17 And Jesus said to him, “Blessed are you,
Simon Barjona, because flesh and blood did not reveal this to
you, but My Father who is in heaven. V. 16-17.
I confess that there is a difference between calling Jesus the Christ (which means Messiah, Savior, the Anointed One) and calling him Lord. However, as shown in the passage above from John, Lord was intended to mean something much different in Christian theology from the Roman lords and masters.
It is beyond the scope of this answer to define exactly what Paul means by "Holy Spirit" or the "Spirit of God." I think, however, that we can safely include the concept in Christian theology of the time. See above in Matt. 16:13-20 and John 13:13-14. That would starkly differentiate the use of Lord from that in contemporary Roman society.
3 Therefore I make known to you that no one speaking by the
Spirit of God says, “Jesus is accursed”; and no one can say,
“Jesus is Lord,” except by the Holy Spirit.
Obviously, being a Christian and cursing Jesus does not go together. Only a Christian will say, "Jesus is Lord." I think that agrees with what Jesus was saying, according to the Gospels.