Sneaky: That's actually a deep question! I'd like to try to answer it.First we have to ask ourselves, "how important is castling in this situation?" Obviously White has to free that queen's rook, but Kd2 or Ke2 would accomplish that.
In other words, could it be wise to play Kd2/Ke2 instead of O-O-O? It's a case of pros and cons. With Ke2 or Kd2, your queen's rook will be free, and king would be more centralized, ready for the endgame. On the other hand, with O-O-O, your queens rook will be instantly deployed on the d-file, but there will be less king safety--and with queens on the board, that is a serious concern.
When Anand played 17.O-O-O, he showed us where his values lie: in this position he preferred the king-safety and instant rook development over centralizing his king and delayed rook development. This follows the old rule of thumb, that with queens on the board you should seek shelter for your king.
And yet, as you show, White would not have the option of O-O-O if Black played 16...Qh4+. Then he would have been forced to play Kd2 or Ke2. (Kd1 is poor because the rook is still not free.) Black could have forced White into doing something which he clearly didn't prefer! So why not do it?
The answer must have to do with the element of TIME. If Black played 16...Qh4+ 17.Ke2 and it may be true that Black is now wise to retreat the queen (again!). For example, what if White plays g5 to trap in queen inside the pawns, then routes the knight to g2 (d1,e3,g2) where it attacks her? Eek!
So Black inconveniences White, but if Black is forced to move the queen back again, it comes at the cost of what we call a "tempo."