A move must follow the piece's movement rule and leave its own king out of check. A rook moves along an open row or column. When it blocks an attack on its king, moving it away may be illegal.
Worked example
White's rook on e2 lies between Black's rook on e8 and White's king on e1. Moving the white rook to e3 keeps something between the attacker and the king. Moving it to f2 opens the whole e-file and leaves the king in check.
A Shield on the e-File
White has king e1 and rook e2. Black has king a8 and rook e8. All other squares are empty; White moves next. A rook cannot attack through another piece. The white rook may move along the e-file while protecting its king, or capture the attacker on e8. It cannot move onto its own king on e1.