It’s been a while since I played an earlier edition, but 5e makes reach much simpler and purely additive. I don’t have my DMG handy, but the text in the SRD is “This weapon adds 5 feet to your reach when you Attack with it, as well as when determining your reach for Opportunity Attacks with it” (emphasis mine).
5e does not have a mechanic for getting within the reach of a polearm weapon as you describe – if you’re within reach, you are a valid target for Attack actions or Opportunity Attack reactions (barring status effects or other external factors). Polearm weapons increase your reach to 10’, but there is no language stating that this creates a bubble of 5’ within that reach where you cannot make Opportunity Attacks.
“While you are wielding a glaive, halberd, pike, quarterstaff, or spear, other creatures provoke an opportunity attack from you when they enter the reach you have with that weapon.”
This language creates an interesting situation that @Schroeder has pointed out. On one hand, the creature was within 10’ while within the wall, which does put them within reach range of your Polearm Master’s weapon. If we look at this strictly from the viewpoint of linear distance, when they exit the wall they are moving within your reach and do not trigger an Opportunity Attack. On the other hand, that interpretation implies your reach can include the walls around you as space you can affect.
I think this is a poor approach to take, for a couple of reasons.
- Most importantly to me, you are explicitly taking away a PC’s feat here. Polearm Masters hit things as they approach. That’s the thing they do best. Explicitly taking away an option they spent an ability point increase on does not seem like a good approach to ensure your players are having a good time.
- As mentioned, this approach assumes Reach can include spaces you can’t enter or affect. If your reach extends into the wall, can you attack the creature while they are in the wall? If so, they get their Polearm Master OA when the creature moves into the section of wall within their reach.
Attacking a target in a wall doesn’t seem reasonable to me, barring some sort of siege weapon. To my mind, a reasonable (and player empowering) interpretation is to view reach as something that goes out up to ten feet, for polearm masters, and walls constrain or interrupt that. When the target exits the wall, they are entering the players reach.
In the case of your wall-travelling creature, they have exited the wall and into a space the player can target within their reach. RAW, this makes them a valid target for Opportunity Attack. As the player has the Polearm Master feat, this also means they are able to make an Opportunity Attack in that moment.
If this doesn’t jive with your sense of how a polearm works (the pointy bit is very far away in that moment), remember that polearm fighting historically was not all about the pointy end. You can club people with the side, jab them with the butt end, etc. Many longer polearms had counterweights on the butt to both make wielding them easier, as well as for hitting people with in these more up close situations. This is called out in the Polearm Master feat, which adds a bonus attack action with the weapon’s opposite end:
“When you take the Attack action and attack with only a glaive, halberd, quarterstaff, or spear, you can use a bonus action to make a melee attack with the opposite end of the weapon. This attack uses the same ability modifier as the primary attack. The weapon's damage die for this attack is a d4, and it deals bludgeoning damage.”
The core rationale for me making this argument is that ultimately, we are talking about a single attack. From the DM perspective, it’s one attack, it’s not a big deal. From the player perspective, it is one of the only things they will do in a round. A Polearm Master has also sunk significant player resources (a feat) into getting better at OAs. Let them roll their attack to bonk the baddie as it bursts out of the wall, they’ll feel great.