The white king generally has to stick to black squares on its way to h4, otherwise the f1-bishop will check (avoiding Bxg2 mate) and enable the f2-pawn to promote, e.g. 1. Kc5 Bg1 2.Kd6 Bh2 3.Ke6 Bc4+ 4.Ke7 f1=Q freeing Black.
But if the king moves on black squares only, it will reach h4 at the wrong time. The piece ends up using an even number of moves, allowing Black's dark-squared bishop to similarly make an even number of moves and thus play ...Bh2 at the right moment to stop Rxg3 mate.
White therefore wants to waste a move and play Kxh4 one move later, which would leave Black in zugzwang and compelled to play the unguarding ...Bg1. In order to waste a move or "lose a tempo", the king has to "triangulate" and that requires visiting a white square. The only white square that the king can use for this purpose, without allowing the f1-bishop to check, is a8. So that's why the solution begins with the king aiming for that corner square.
I picked up chess a few weeks ago, mostly played against perfect-2-moves-ahead AIs so far but that wasn't particularly fun so I've moved to chess problems, to improve my intuition for seeing possible moves, building an imaginary visual overlay of controlled squares and getting a quick overview over the board and permutations down.
I found "Sam Loyd and His Chess Problems", which seemed like a nice start after most random M3 puzzles I found online were usually quick to solve for me (I'm not assuming I'm a good player now just because I'm generally okey at puzzle games; I know every real game is fundamentally different, I'm doing this to build intuition). Here's a PDF of that book: https://www.kunstschach.ch/docs/White_Sam%20Loyd%20and%20his%20chess%20problems%201913.pdf
No. 5 puzzles (hah!) me. I understand that the idea behind the problem is that black cannot make any legal moves except repeating Bg1 <-> Bh2, and since white has much fewer pieces, you don't want that to change - so you're trying to achieve mate with the only piece that's not busy with that task, which is the king. The only way to do this is by taking h4. The solution moves the king across the entire upper half of the board, almost exclusively diagonally too - up to a8, zig-zagging across to h6 and then down, avoiding the knight's controlled spaces, to take the pawn.
But... why? Why does the solution take such a huge detour? I can't see any reason to not take the shortest route north past kf6, just making sure to end up taking the pawn at an uneven number of moves so that the moving bishop ends up at g1 and rh3 can take kg3 and win the game. What am I missing?