What are the motivations behind pawn moves on a and h files? Sometimes when there are no clearly optimal moves, a computer or a human master player would push their pawns on a and h files (the edges of the board), for no clear reasons.  What would be the motivations behind such moves?
The question is extremely open, as these pawns may be moved for many reasons depending on the position you are facing. In a general sketch, you may consider five kind of a and h pawn moves:


To create some luft for the king, that is, avoid once and for all the back rank threats.

[FEN "r5k1/5ppp/8/8/8/8/5PPP/1R4K1 w - - 0 1"]



In this position, neither rook can leave the back rank, because if they do Rb8 for white or Ra1 for black are checkmate (this is called to have a weak back rank). For this reason, it is useful to move h4 for white or h5 for black, in order to be able to escape via h2 or h7 if the rook leaves the back rank.


To attack the enemy castled king, as opening the h file usually comes with dangerous threats of infiltration with the major pieces near the king.

[FEN ""]
1. e4 c5 2. Nf3 d6 3. d4 cxd4 4. Nxd4 Nf6 5. Nc3 g6 6. Be3 Bg7 7. f3 O-O 8. Qd2 Nc6 9. Bc4 Bd7 10. O-O-O Rc8 11. Bb3 Ne5 12. h4 {This is a main line in the Yugoslav Attack of the Dragon. The plan is to go full aggression on the kingside: blast open the `h` file, play `Bh6`, exchange bishops and continue `Qh6` with mate threats on `h7`. To parry all the threats that white will make, precision is essential, since many good looking moves are actually horrible blunders.}

To gain space, either by a further advance of an adjacent b or g pawn or by avoiding a piece to be pushed away by a pawn.

[FEN ""]
1. e4 c5 2. Nf3 g6 3. d4 cxd4 4. Nxd4 Bg7 5. c4 Nc6 6. Be3 Nf6 7. Nc3 O-O 8. Be2 d6 9. O-O Bd7 10. Qd2 Nxd4 11. Bxd4 Bc6 12. f3 a5 {This is a main line in the Maroczy Bind of the HyperAccelerated Dragon. With this move, black makes sure the `b4` advance that white wants to make is delayed at least for some moves. Moreover, as is seen in the following moves, this allows black's knight to get a comfortable home in `c5`, as for the moment he cannot be dislodged.} 13. b3 Nd7 14. Be3 Nc5 {And white will have to prepare his plan of gaining space on the queenside thoroughly.}



Another fact (credit to JiK for pointing it out) that encourages the move of an a or h pawn before moving the corresponding b or g pawn is that the former often do not leave behind as big holes (or any holes at all) as the latter. This is because the pawns on the edge on the board only protect one square on the 3rd/6th rank, and many times the bishop pawn wasn't moved and already covers it, or in the event of leaving a hole, the queen's knight's file usually is away from the main action, so it may not be very important (one should consider very carefully whether leaving a hole in front of one's king).


To defend against pins in order to drive away enemy pieces or to take away a concrete square from them.

[FEN ""]
1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. d3 Nf6 5. c3 d6 6. O-O O-O 7. Bb3 a6 8. Nbd2 Ba7 9. h3 {This is a main line in the Giuoco Pianissimo. With the last move, white avoids the unpleasant pin of the `c3` knight by `Bg4`. This also creates some breathing space for the king, but that is not the main idea behind the move. The reason it is played now and not a few moves before is mainly because you are prioritizing piece development.}

To preserve a bishop from getting exchange (credit to Dag Oskar Madsen for pointing it out). Usually bishops are slightly better than knights, and giving your opponent the bishop pair would require to play with extra care in the endgame.

[FEN ""]
1. d4 Nf6 2. Nf3 g6 3. Bf4 Bg7 4. e3 O-O 5. Be2 d6 6. h3 {This is a main line in the London system. With the last move, white gives the `Bf4` a retreat in the event of `Nh5` while keeping it on the `h2-b8` diagonal, helping to tighten the grip on the dark squares. The reason `Nh5` earlier (when white pushes `e3`) does not work so well is because it allows a chronicle weakening of black's kingside, and the reason `Nh5` does work if `h3` is not played is half-positional half-tactical.}



This last position is quite complex, if interested you may want to look at this link for some variations.

Conclusion:

It's important to bear in mind that every move should be useful, as you must contribute to the global synergy of your pieces in order to achieve a better position. Usually at master or computer level, when they do not find the optimal move (although the computer usually does) or placement for their pieces, they always tend to achieve some kind of positional advantage, and those listed above are mainly of this kind.

EDIT: Examples have been added and a fifth case has been added.