Matthew 5:3-12 and Luke 6:20-26 are parallel passages that constitute the beginning of the "Sermon on the Mount". They are commonly called "The Beatitudes", which basically means "blessings".
The format of a "beatitude" is to mention a virtue, and then a blessing associated with that virtue. For those who believe in a works-based Salvation, the "virtues" are seen as criteria for getting into Heaven, and the "blessings" are seen as broadly describing getting into Heaven.
With that in mind, let's go through this passage and determine what's being discussed.
First, here are the Beatitude passages in their entirety:
Matthew 5:3-12
3 Blessed are the poor in spirit: for theirs is the kingdom of heaven.
4 Blessed are they that mourn: for they shall be comforted.
5 Blessed are the meek: for they shall inherit the earth.
6 Blessed are they which do hunger and thirst after righteousness: for they shall be filled.
7 Blessed are the merciful: for they shall obtain mercy.
8 Blessed are the pure in heart: for they shall see God.
9 Blessed are the peacemakers: for they shall be called the children of God.
10 Blessed are they which are persecuted for righteousness' sake: for theirs is the kingdom of heaven.
11 Blessed are ye, when men shall revile you, and persecute you, and shall say all manner of evil against you falsely, for my sake.
12 Rejoice, and be exceeding glad: for great is your reward in heaven: for so persecuted they the prophets which were before you.
Luke 6:20-23
20 And he lifted up his eyes on his disciples, and said, Blessed be ye poor: for yours is the kingdom of God.
21 Blessed are ye that hunger now: for ye shall be filled. Blessed are ye that weep now: for ye shall laugh.
22 Blessed are ye, when men shall hate you, and when they shall separate you from their company, and shall reproach you, and cast out your name as evil, for the Son of man's sake.
23 Rejoice ye in that day, and leap for joy: for, behold, your reward is great in heaven: for in the like manner did their fathers unto the prophets.
Notice that both passages terminate with "great is your reward in Heaven" - and that's precisely what's being discussed. These passages give practical examples of the virtues that add to a believer's inheritance in the Kingdom of God, which is what Matthew 5:3, 5:10, and Luke 6:20's references to the "Kingdom of God/Heaven" are referring to.
This is evidenced by the fact that Christ is plainly discussing "works" when mentioning the virtues, and as covered at length in this article, God will "reward every man according to his works" (Matthew 16:27, Revelation 22:12).
However, this inheritance of the Kingdom is in distinction from entrance into the Kingdom, which is discussed later in Matthew chapter 5:
Matthew 5:20
20 For I say unto you, That except your righteousness shall exceed the righteousness of the scribes and Pharisees, ye shall in no case enter into the kingdom of heaven.
Above, Kingdom entrance is predicated on being more righteous than the most stringent Law keepers on the planet at that time. For reference, when offering evidence of his obedience to the Law, the Apostle Paul simply mentions that he was a Pharisee (Philippians 3:4-6). Some of them were unrighteous hypocrites, as the Lord speaks of elsewhere, but not all of them were.
As is discussed in this article, the only way to become "righteous" in any sense before God is by faith, and faith apart from the works of the Law is the only way to obtain the "righteousness of God":
Philippians 3:9
9 And be found in him, not having mine own righteousness, which is of the law, but that which is through the faith of Christ, the righteousness which is of God by faith:
All of the virtues mentioned in The Beatitudes are encapsulated in the Law, and the Bible is redundantly clear that we are saved by faith without keeping the Law, both points which are discussed in this article. If these passages were giving a list of things to do to enter Heaven, then we would unequivocally be saved by keeping the Law.
Therefore, we have established what this passage is not teaching - that the virtues - the works - that add to your inheritance, play a role in your Salvation from Hell, as we are saved "not of works" (Ephesians 2:9), and "not by works of righteousness which we have done" (Titus 3:5), which The Beatitudes are prime examples of.
In almost all of the blessings given in the passages, it's easy to see that they are describing exaltation and a better experience in the Kingdom. However, three of them, which in particular could be confusing, warrant further discussion:
Matthew 5:7-9
7 Blessed are the merciful: for they shall obtain mercy.
8 Blessed are the pure in heart: for they shall see God.
9 Blessed are the peacemakers: for they shall be called the children of God.
These verses, respectively, are testifying that:
In summary, The Beatitudes are about the Kingdom, and aimed at those already assumed to be entering the Kingdom.
The passage in Luke finishes with "The Woes", which are like inverted Beatitudes:
Luke 6:24-26
24 But woe unto you that are rich! for ye have received your consolation.
25 Woe unto you that are full! for ye shall hunger. Woe unto you that laugh now! for ye shall mourn and weep.
26 Woe unto you, when all men shall speak well of you! for so did their fathers to the false prophets.
I believe that the scope has not changed in the above verses - they are aimed at believers, and speak to a diminished inheritance in the world to come if one lives an easy life of excess down here on earth.
Luke 6:25's mention of "mourning" and "weeping" is the only potentially confusing snippet, but I believe that every single believer to ever live will weep at the Judgment Seat of Christ, as everyone will see at least some of their works "burned", and will therefore "suffer loss" (1 Corinthians 3:15) of at least a portion of what they could have had.
Those who go to Heaven are not unable to weep, but rather, unlike down here, they will be consoled by the Lord Himself, who "shall wipe away all tears from their eyes" (Revelation 7:17, 21:4). That is to say, after the Judgment Seat of Christ is over, I expect that even a believer who lived a mostly squandered life will be restored to joy in relatively short order - they will not sorrow over their loss for all of eternity. They will be in a glorified body, they will be living in the New Man entirely, and will be able to serve God joyfully for eternity, despite their loss.
These passages both deal with believers, the Kingdom, and the inheritance that every believer stands to gain or lose. They do not teach that works play a role in getting into the Kingdom in the first place.