user4049: 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?

user2429: @pablo has listed some of the common motivations for moving rook pawns. I will mention some uncommon but interesting ones. I have used all of these in real games. 

Set up a queen trap to develop a bishop. 
 [FEN ""]

 1. e3 e5 2. Qf3 d5 3. Nc3 Nf6 4. d4 e4 5. Qg3 h6 $1 (5... Bd6 $6 6. Qxg7 Rg8 7.
  Qh6) 6. Nge2 Bd6 7. Qxg7 Rh7!

Prevent a pinning Bishop from being dislodged, as in the Ruy Lopez. 
 [FEN ""]

 1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Bxc6 dxc6 5. O-O Bg4 6. h3 h5 $5 7. hxg4 $2 (
 7. d3!) 7... hxg4 8. Nxe5?? (8. d3 gxf3 9. Qxf3 Qh4 10. Qh3 Qxh3 11. gxh3 Rxh3)
 8... Qh4 9. f4 g3 10. Nf3 Qh1#



user3890: 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.

4049: <p>Sometimes when there are no clearly optimal moves, a computer or a human master player would push their pawns on <code>a</code> and <code>h</code> files (the edges of the board), for no clear reasons.  What would be the motivations behind such moves?</p>
 2429: <p>@pablo has listed some of the common motivations for moving rook pawns. I will mention some <strong>uncommon</strong> but interesting ones. I have used all of these in real games. </p>

<ol>
<li><p>Set up a <strong>queen trap</strong> to develop a bishop. </p>

<pre><code> [FEN ""]

 1. e3 e5 2. Qf3 d5 3. Nc3 Nf6 4. d4 e4 5. Qg3 h6 $1 (5... Bd6 $6 6. Qxg7 Rg8 7.
  Qh6) 6. Nge2 Bd6 7. Qxg7 Rh7!
</code></pre></li>
<li><p>Prevent a <strong>pinning Bishop</strong> from being dislodged, as in the Ruy Lopez. </p>

<pre><code> [FEN ""]

 1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Bxc6 dxc6 5. O-O Bg4 6. h3 h5 $5 7. hxg4 $2 (
 7. d3!) 7... hxg4 8. Nxe5?? (8. d3 gxf3 9. Qxf3 Qh4 10. Qh3 Qxh3 11. gxh3 Rxh3)
 8... Qh4 9. f4 g3 10. Nf3 Qh1#
</code></pre></li>
</ol>
 3890: <p>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 <code>a</code> and <code>h</code> pawn moves:</p>

<ol>
<li><p>To create some luft for the king, that is, avoid once and for all the back rank threats.</p>

<pre><code>[FEN "r5k1/5ppp/8/8/8/8/5PPP/1R4K1 w - - 0 1"]
</code></pre></li>
</ol>

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

<ol start="2">
<li><p>To attack the enemy castled king, as opening the <code>h</code> file usually comes with dangerous threats of infiltration with the major pieces near the king.</p>

<pre><code>[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.}
</code></pre></li>
<li><p>To gain space, either by a further advance of an adjacent <code>b</code> or <code>g</code> pawn or by avoiding a piece to be pushed away by a pawn.</p>

<pre><code>[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.}
</code></pre></li>
</ol>

<p>Another fact (credit to <a href="https://chess.stackexchange.com/users/1761/jik">JiK</a> for pointing it out) that encourages the move of an <code>a</code> or <code>h</code> pawn before moving the corresponding <code>b</code> or <code>g</code> 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).</p>

<ol start="4">
<li><p>To defend against pins in order to drive away enemy pieces or to take away a concrete square from them.</p>

<pre><code>[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.}
</code></pre></li>
<li><p>To preserve a bishop from getting exchange (credit to <a href="https://chess.stackexchange.com/users/1485/dag-oskar-madsen">Dag Oskar Madsen</a> 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.</p>

<pre><code>[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.}
</code></pre></li>
</ol>

<p>This last position is quite complex, if interested you may want to look at <a href="http://www.365chess.com/opening.php?m=22&amp;n=925853&amp;ms=d4.Nf6.Nf3.g6.Bf4.Bg7.e3.O-O.Be2.d6.O-O.Nh5.Bg5.h6.Bh4.g5.Nfd2.gxh4.Bxh5.e5.c3&amp;ns=7.14.20.48.472.548.473.2005.8227.9575.8752.116377.206132.238612.206133.238613.328161.354034.328162.765282.925853" rel="nofollow noreferrer">this</a> link for some variations.</p>

<p><strong>Conclusion:</strong></p>

<p>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.</p>

<p><strong>EDIT:</strong> Examples have been added and a fifth case has been added.</p>
