Why is a6 strong in this position? I was spectating an online simul given by a GM (this game in particular) and as the game was played I was very surprised to see GM Chessweeb play 24... a6.
Here is the position.
[Title &quot;Black to move&quot;]
[StartFlipped &quot;1&quot;]
[fen &quot;7Q/ppk1qp2/4p3/3pPp1P/5P2/2P5/PP4r1/1K1R4 b - - 0 24&quot;]

I was expecting a continuation like
24... Qh4
25. h6 Qxf4
Stockfish confirms that a6 is indeed the best move but I'm having trouble understanding why that is. The only thing I can think of is perhaps a6 gives the king a hideout to prevent future perpetual check?
You're correct. The idea of 24...a6 is to allow the king to avoid a perpetual. This could be of relevance if Black's queen moves away to go after White's king (e.g., ...Qc5). It could also be useful for the king to hide on a7 if things go haywire and a dangerous attack happens, such as the h-pawn promoting or White's rook getting involved. Although, in the position before 24...a6, Stockfish gives an evaluation of 0.00 no matter whose move it is. So purely in an objective sense, ...a6 isn't a necessary move -- but practically it's quite nice. Your anticipated move of 24...Qh4 is also evaluated at 0.00 by Stockfish, so it's just as good.
One interesting line goes 24...a6 25.h6 (White has other moves that are fine too) 25...Qc5. Now White's going to get mated from ...Qf2 if he's not careful. For example, 26.Qe8 Qf2 27.Qe7+ Kb8 28.Qf8+ Ka7. Now White can't stop the dual threats of ...Qxb2# and ...Qc2+ (picking up the d1-rook with mate). Another faulty try is 26.Qg7. The idea is that 26...Rxg7 27.hxg7 sees White about to promote, leaving him up a rook. However, Black has 26...Qf2, and 27.Qxf7+ Kb6 28.Qxe6+ Ka7 sees Black's king being safe, again thanks to the a6-pawn. Therefore, White's only 26th move which maintains equality is 26.Ka1!, preparing to defend with Rb1 if needed.