My short answer would be that this saying directed at the disciples of John the Baptist, whom he is addressing at the time.
The Greek phrase is exactly the same in both passages;
καὶ μακάριός ἐστιν ὃς ἐὰν μὴ σκανδαλισθῇ ἐν ἐμοί.
where the word "offend" is σκανδαλίζω (skandalizō; viz. "scandal") - in the passive voice in the two verses.
The word has a fairly wide scope in the lexicons, including "cause to sin", "give up one's faith", "reject", "anger", "shock", "offend", "cease believing".1 The lexicons in and by themselves will not shed much meaning here, I think.
It might be helpful to recall, I think, that the saying was part of Jesus' response to John's disciples, whom he sent from prison:
Now when John had heard in the prison the works of Christ, he sent two of his disciples, And said unto him, Art thou he that should come,
or do we look for another? Jesus answered and said unto them, Go and
shew John again those things which ye do hear and see: The blind
receive their sight, and the lame walk, the lepers are cleansed, and
the deaf hear, the dead are raised up, and the poor have the gospel
preached to them. And blessed is he, whosoever shall not be offended
in me (Matthew 11:2-6)
When the men were come unto him, they said, John Baptist hath sent us unto thee, saying, Art thou he that should come? or look we for
another? And in that same hour he cured many of their infirmities and
plagues, and of evil spirits; and unto many that were blind he gave
sight. Then Jesus answering said unto them, Go your way, and tell John
what things ye have seen and heard; how that the blind see, the lame
walk, the lepers are cleansed, the deaf hear, the dead are raised, to
the poor the gospel is preached. And blessed is he, whosoever shall
not be offended in me (Luke 7:18-26)
The understanding here in antiquity was that John the Baptist himself had no doubts about Jesus, but understood that his disciples may have and, for that reason, send them to Jesus directly so that they could begin to be His disciples rather John's. As John the Evangelist recounts, John the Baptist says on another occasion, He must increase, but I must decrease (John 3:30).
John did not ask as if he himself did not know Christ. How could this
be when he had borne witness to Him saying Behold the Lamb of God?
(John 1:29). But because his disciples were jealous of Christ, John
sent them to acquire more evidence, so that by seeing the miracles
they might believe that Christ is greater than John (Theophylact,2 Explanation of the Holy Gospel According to St. Matthew)
With respect to Jesus' saying Blessed is he, whosoever shall not be offended (μὴ σκανδαλισθῇ) in me, we can borrow an English cognate and say that what is meant here is that they would not be "scandalized". John Chrysostom (4th c. Byzantine) explains:
Knowing therefore, as being God, the mind
with which John had sent them, He straightway cured blind, lame, and many others; not to teach him (for how should He him that was convinced), but these that were doubting: and having healed them, He saith,
Go and show John again those things which ye do hear and see; the blind receive their sight, and the lame walk, and the lepers are cleansed, and the deaf hear, and the dead are raised up, and the poor have the gospel preached unto them. And he added, And blessed is he, whosoever shall not be offended in me, implying that He knows even their unuttered thoughts. For if He had said, "I am He," both this would have offended them, as I have already said; and they would have thought, even if they had not spoken, much as the Jews said to Him, Thou bearest record of Thyself (John 8:13). Wherefore He saith not this Himself, but leaves them to learn all from the miracles, freeing what He taught from suspicion, and making it plainer. Wherefore also He covertly added His reproof of them. That is, because they were “offended in Him,” He by setting forth their case and leaving it to their own conscience alone, and by calling no witness of this His accusation, but only themselves that knew it all, did thus also draw them the more unto Himself, in saying, Blessed is he, whosoever shall not be offended in me (Homily XXXVI on Matthew)
The interpretation here is also somewhat complicated by the fact that the King James Version is using "offend" in a sense that is now obsolete, with the meaning of "to be a stumbling block, or cause spiritual or moral difficulty" (see Complete Oxford English Dictionary). At the time, this was a perfectly good word to use at the time of the KJV translation (just prior to 1611), but, according to the Oxford English Dictionary, the usage became obsolete sometime after 1658.
1. e.g. Newman's Concise Greek-English Dictionary of the New Testament,Swanson's Dictionary of Biblical Languages with Semantic Domains, Louw-Nida Greek-English Lexicon of the New Testament based on Semantic Domanins
2. 11th c. Byzantine Greek