TL;DR: if you use PHB rules (diagonals are free), and end your turn at least 20' behind the NPC, running on walls is free. It only costs the total horizontal distance.
If you use the DMG rules (every 2nd diagonal costs 10'), and end your turn at least 20', running on walls costs 10' of movement, plus your horizontal distance.
We can break this question into three parts:
- How far up can an attacker reach?
- How do diagonals work?
- What is the minimum movement I have to expend to do this?
How far can an attacker reach?
PHB pg 146:
A melee weapon is used to attack a target within 5 feet of you
While plenty of medium creatures are greater than 5' tall, D&D abstracts a medium creature to be a 5'x5'x5' cube when dealing with grid spacing (it's the space they control, but their reach is measured from the outside of their controlled range).
Given that, an NPC/PC can attack a creature which passes <5ft above their head, or <10ft above the ground.
So for you to get past the enemy without provoking an OA, you will need to pass 10ft above the ground they are standing on.
How do diagonals work?
RAW, diagonals are the same distance away as the adjacent squares (PHB pg 192). This means that in 2 dimensions, you measure your movement in both dimensions, then pick the greater one. However, there is an optional rule in the DMG (pg 252) that introduces a cost to them. Namely, that every second diagonal costs 10', rather than 5'.
So, to sum up, Base rules says that diagonals are free, variant rules says that every second costs 10'. We will continue with the base rules, because they're the base rules.
Moving through diagonal spaces
RAW, you cannot move through a diagonal if either of the spaces you would pass through to get there are blocked with an obstacle. This could be a tree or a building. Given this, it is clear that you pass through these squares, even if you do not count the movement this way. This means that if you are attempting to avoid entering someone's threat range, you must not move diagonally around this range.
What is the minimum movement I have to expend to do this?
If we assume base rules, then your first move is to get 10' above your enemy. But your enemy can reach the diagonal square above them, so you need to get 10' above the ground while you are still 10' away from them. This will cost you 10'.
Now, you need to pass over their head. Since they threaten squares 5' on each side of them, and you need to avoid having your diagonals pass through the threatened space, you need to move 20' along the wall. This will cost you 20'.
Finally, you need to get to the ground. Fortunately, you can fall for free, however, since you are falling 10', you will take 1d6 falling damage. This can be avoided by taking a reaction to use the Monk's Slow Fall ability or by running down the wall.
If you run down the wall and intend to keep running, then this is essentially free, as you can move one space horizontally and vertically with the same movement. If you want to stop within 20' of your attacker, then you will need to spend 10' of movement to get to the ground.
This will either cost you your reaction, 1d6 hit points, or 10' of movement if you want to stop within 20'. If you wish to continue moving afterwords, this will not cost you any movement.
So, as long as you have at least 20' between you and your opponent, you can move above them without costing any additional movement
Diagram, from side view: (1 is start, 2 is end, N is NPC, X is threat range, - is path)
Continue running: 40' (horizontal distance, 40')
- XXX -
2 XNX 1
Stop Running: 30' + damage or reaction
Bonus, what if the diagonals cost?
The path you travel is the same, but the cost is different. Going 10' up and 10' over now costs 15' of movement. The horizontal movement is the same 20', and the movement down costs 15'.
So for the variant rules, you will have to spend 35', and spend either your reaction (to fall using the monk's slow fall ability), take 1d6 hp (to fall), or spend an extra 15' to hit the ground 15' behind your enemy.
So if you are using the variant rules, provided you have 20' between you and your target, and want to end your turn 20' or more behind them, it will only cost you 10' more than the horizontal distance. If you wish to stop right after them, it will cost 5' extra, plus your reaction, or 1d6 hp