Playing g3 and Bg2 puts the Bishop on the long diagonal. The Bishop is a good defender for the King. White’s plan often includes advancing the f-pawn at some stage.
If Black has a Bishop on c5 (or anywhere on the a7-g1 diagonal), then the f-pawn is pinned and can’t move. Moving the King breaks the pin. Even if there is no pin, moving the f-pawn will always give Black a potential check later, so moving the King off the diagonal is a useful prophylactic move.
A downside to the Bishop being on g2 is that it cannot break a Bg4 pin of a Knight on f3. As such, playing h3 to keep a piece off of g4 is very useful. If Black has his own Bishop on e6 and then Queen on d7, it forms a battery against h3. The pawn would then be hanging.
By playing Kh2, then, White safeguards the pawn while preparing a safe advance of his own f-pawn. That is it in a nutshell.
When analyzing chess games, I often see this odd-looking setup:
Can anyone explain me the idea behind this, or are the players gone mad?