When castling, the rook always lands on the square the king passed through.
So it's illegal because the king would be moving across an attacked square.
However the rook can move through an attacked square when castling. For example
If you need help, please contact our Help and Support team.
Can you castle if your rook lands on an attacked square, is this the same as passing through check.