confusing castling
You are asking if white plays 22. Bf6 I presume. The reason black can castle is that even though the bishop is attacking the h8 rook, the king will not 1) cross the path of the bishop's attacking squares, and 2) the king will not end up on an attacking square. Whether or not the rook is or can be attacked does not matter.
Similar situation happened in this game: