The rules of castling is as follows.
You move the king two squares towards a rook. Then you move the rook to the square between from where your king came from and the square where it came.
You cannot castle when your king has previously been moved, when the rook has moved, there is no pieces between the king and the rook, and if the king is not in chess in any of his three squares involved.
Right?
Okay look at this position. Find mate in two!
If white promotes his pawn to a rook, 1 e7-e8R, black moves his king 1 ... Ka2-b2 the we see that the rook hasn't been moved (a virgin rook), there are no pieces beween the king and the rook, and the king is not attacked. Then the castling is possible, and is denoted 2. 0-0-0-0. In this case a mate.
This was the loophole. Worked by the old rule. Now the rule says:
"FIDE rule 3.8.a.ii. ‘castling'. This is a move of the king and either rook of the same colour
on the same rank, counting as a single move of the king and executed as follows: the king is transferred from its original square two squares towards the rook, then that rook is transferred to the square the king has just crossed."
(the rule change in bold)