It's perfectly legal, indeed Tony. Another misconception I've met with,
is that some (not here as far as I know) are convinced one can't castle
anymore once your King HAS BEEN checked, but that was undone by
either taking the checking piece or placing one of your own in between.
Of course, it's perfectly legal within FIDE-rules to castle after that. Jan
You may castle providing neither rook nor king has moved, the king is
not in check at the time you wish to castle or the king will not pass
through check during castling.
The square the rook sat on before castling may be under attack,
however. On the queenside, both the a1 (a8 for Black) and b1 (b8 for
Black) squares may be under attach during a queenside castling
move, as the king never passes through those squares when castled.
Yes, the rook can be attacked by a piece when a castling move is
made. Only the king cannot be attacked or have to pass through a
square under attack.
Unfortunately, the rook cannot be under attack when castling is
completed because on both the queen and kingside the rook lands on
a square the king would have had to pass through.