In any position, you should evaluate the pros and cons of each reasonable candidate move.
The cons of 1.h3 2.g4, as you correctly identified, is a potential weakening of your king. This is a valid concern. However, if you look at it more deeply, is there really a threat to your king safety? Yes, moving the pawns is conceptually dangerous, but it is important to consider the concrete details of the position: all of your pieces are more or less on the kingside, protecting your king, so there is almost no way that he will be able to checkmate you despite the weakening of your king. Even if the black queen teleports to g8 and knight teleports to g6, and black's pawn teleports to f5 as well, you are still not under any kind of devastating attack. It is simply inconceivable for any attack to work out when all your pieces are in good position for defence!
The pros are significant. Firstly, you force black to make a decision that allows you to unpin your knight and make your pieces slightly less awkward. (E.g. if instead 1.Qb3, you have to worry about 1...Bxf3 possibly giving you an endgame liability in doubled pawns; though not that it necessarily is a big problem in this exact position.) Secondly, if 1.h3 Bxf3, you gain the bishop pair, which is good. Even if 1.h3 Bh5 2.g4 Bg6, his bishop is entombed biting into your concrete pawn wall on d3-e4 and absolutely depressed. Black now has to spend time trying to play d5 to reactivate the bishop, which gives you time to do other things to improve your position and puts the onus on Black to find a plan to not have a worse position. Not to mention, the g6 bishop blocks the g7 pawn (black would like to play ...g6, f5 to break, but this is physically impossible). Black's position would be depressing while you have all sorts of ideas on the queenside like eventually getting the rook to a1 or c1 attacking the c6 weakness, or pushing the b pawn to promotion depending on Black's response.
On balance, the pros outweigh the cons, so 1.h3 2.g4 is a good plan.