user2205: Why is castling disallowed when the king is in check or when the square the rook will be placed on is under attack?
What is the rationale behind this ruling?

user11245: Because that would be cheating.  Well, to be fair, the reason is to make it reasonable that when all of the squares surrounding a king and the square it stands on are attacked by the opponent, the defender cannot simply warp away and out of trouble, while simultaneously delivering a new defender in the fray.  The move would simply be too powerful.
However, you are allowed to do this:
[FEN "1r6/p2nkp1p/2B1pb1B/2p5/6r1/2P5/PP3P1P/R3K2R w KQ - 0 21"]
[Event "Todd Southam Memorial"]
[Site "Toronto"]
[Date "2004.06.13"]
[White "Krupnov, Maxim E"]
[Black "Smith, Hazel"]
[Result "1-0"]
[WhiteElo "2361"]
[BlackElo "2051"]
[SetUp "1"]
[EventType "schev (rapid)"]

1. Be3 Rxb2 2. Bxd7 Kxd7 3. O-O-O+ Kc6 4. Kxb2 {and White won in 42 moves} 1-0


user4362: I just posted an answer to this question How did castling originate? and I think it offers a missing part of the answer to this questions as well: What the rationale is, behind not being able to castle out of check.
Historically castling was probably two moves (the rook move and the king's leap), that were merged into a double move, because they basically always followed directly one after the other. Just like the double move of the pawns.
And just like you cannot escape capture from an enemy pawn, by just moving past it, you cannot escape check by just castling: In both cases the "double move" is dissected into the two original moves - the pawn can be taken en passant and the king could still be taken after the rook move, making castling illegal.
In both cases the rationale is speeding up the game, without changing what was possible before.

user1816: The way I always understood castling is that it allows the player to move his king to safety. But this privilege does not come for free - it comes at the cost of a tempo. If a player was allowed to castle out of check, or over a checked square, then it allows him to postpone this powerful move until the very latest, effectively removing the penalty from the privilege.
For me, this rule has nothing to do with how the king (or any other pieces) move. It has to do with achieving a balance between attacking play and defensive play. Just like how a goal keeper in football can handle the ball in his penalty area (but not if it was back-passed to him by one of his own players), so the rule of castling is there to ensure that you get a defensive edge, but not for free. You have to work it into your strategy.

user167: One rationale that I can think of for not allowing the king to move through check parallels that behind the possibility of capturing en passant after a pawn makes a two-square advance.

The typical pawn move is just a single square forward, and the possibility of advancing two squares on a pawn's first move was a relatively late addition to the game in historical terms. Since the "nature" of a pawn had long been to make a single square advance, when that new sort of pawn move came into being, the en passant capture was a natural counterpart: the pawn doesn't "jump" two squares ahead, but rather "marches" through the intermediate square, and an opposing pawn is thus allowed to capture en passant on the following move if it is in position to have captured the advancing pawn at the intermediate square.
With that explanation in mind, let's consider your rule. Like pawns, a king's typical, natural movement is only a single square in distance. And like the pawn's two-square advance, castling is a relatively new addition to the rules of chess that is intended to speed the game up. So just as the en passant capture reinforces the pawn's nature as a one-square mover, the rule prohibiting a king to castle through a checked square reinforces the king's nature as a one-square mover. He is thought of not as gliding over the checked square, but rather trudging through it. And just as an opponent's pawn has a chance to capture en passant, an opponent's piece guarding the intermediate castling square would be given the right to capture the king. Since that's not a legal part of chess, castling through check in the first place isn't either.

As for why castling is disallowed just because of the king being in check, I'm not so sure, but I'll speculate. If, in the analogy between chess and war, we think of a check to the king as a wounding attack, less severe than the lethal checkmate but damaging nonetheless, then it's reasonable to insist that the hobbled king can't make a swift, immediate escape via castling. But maybe that's just how I think of it.

2205: <p>Why is castling disallowed when the king is in check or when the square the rook will be placed on is under attack?</p>

<p>What is the rationale behind this ruling?</p>
 11245: <p>Because that would be cheating.  Well, to be fair, the reason is to make it reasonable that when <em>all of the squares surrounding a king and the square it stands on are attacked by the opponent</em>, the defender cannot simply <em>warp</em> away and out of trouble, while simultaneously delivering a new defender in the fray.  The move would simply be too powerful.</p>

<p>However, you <em>are</em> allowed to do this:</p>

<pre><code>[FEN "1r6/p2nkp1p/2B1pb1B/2p5/6r1/2P5/PP3P1P/R3K2R w KQ - 0 21"]
[Event "Todd Southam Memorial"]
[Site "Toronto"]
[Date "2004.06.13"]
[White "Krupnov, Maxim E"]
[Black "Smith, Hazel"]
[Result "1-0"]
[WhiteElo "2361"]
[BlackElo "2051"]
[SetUp "1"]
[EventType "schev (rapid)"]

1. Be3 Rxb2 2. Bxd7 Kxd7 3. O-O-O+ Kc6 4. Kxb2 {and White won in 42 moves} 1-0
</code></pre>
 4362: <p>I just posted an answer to this question <a href="https://chess.stackexchange.com/questions/486/how-did-castling-originate">How did castling originate?</a> and I think it offers a missing part of the answer to this questions as well: What the rationale is, behind not being able to castle out of check.</p>

<p>Historically castling was probably two moves (the rook move and the king's leap), that were merged into a double move, because they basically always followed directly one after the other. Just like the double move of the pawns.</p>

<p>And just like you cannot escape capture from an enemy pawn, by just moving past it, you cannot escape check by just castling: In both cases the "double move" is dissected into the two original moves - the pawn can be taken en passant and the king could still be taken after the rook move, making castling illegal.</p>

<p>In both cases the rationale is speeding up the game, without changing what was possible before.</p>
 1816: <p>The way I always understood castling is that it allows the player to move his king to safety. But this privilege does not come for free - it comes at the cost of a tempo. If a player was allowed to castle out of check, or over a checked square, then it allows him to postpone this powerful move until the very latest, effectively removing the penalty from the privilege.</p>

<p>For me, this rule has nothing to do with how the king (or any other pieces) move. It has to do with achieving a balance between attacking play and defensive play. Just like how a goal keeper in football can handle the ball in his penalty area (but not if it was back-passed to him by one of his own players), so the rule of castling is there to ensure that you get a defensive edge, but not for free. You have to work it into your strategy.</p>
 167: <p>One rationale that I can think of for not allowing the king to move through check parallels that behind the possibility of capturing <a href="http://en.wikipedia.org/wiki/En_passant">en passant</a> after a pawn makes a two-square advance.</p>

<ul>
<li><p>The typical pawn move is just a single square forward, and the possibility of advancing two squares on a pawn's first move was a <a href="http://en.wikipedia.org/wiki/En_passant#Historical_context"><em>relatively late addition to the game</em></a> in historical terms. Since the "nature" of a pawn had long been to make a single square advance, when that new sort of pawn move came into being, the en passant capture was a natural counterpart: the pawn doesn't "jump" two squares ahead, but rather "marches" through the intermediate square, and an opposing pawn is thus allowed to capture en passant on the following move if it is in position to have captured the advancing pawn at the intermediate square.</p></li>
<li><p>With that explanation in mind, let's consider your rule. Like pawns, a king's typical, natural movement is only a single square in distance. And like the pawn's two-square advance, castling is a <em>relatively new addition to the rules</em> of chess that is intended to speed the game up. So just as the en passant capture reinforces the pawn's nature as a one-square mover, the rule prohibiting a king to castle through a checked square reinforces the king's nature as a one-square mover. He is thought of not as gliding over the checked square, but rather trudging through it. And just as an opponent's pawn has a chance to capture en passant, an opponent's piece guarding the intermediate castling square would be given the right to capture the king. Since that's not a legal part of chess, castling through check in the first place isn't either.</p></li>
</ul>

<p>As for why castling is disallowed just because of the king being in check, I'm not so sure, but I'll speculate. If, in the analogy between chess and war, we think of a check to the king as a wounding attack, less severe than the lethal checkmate but damaging nonetheless, then it's reasonable to insist that the hobbled king can't make a swift, immediate escape via castling. But maybe that's just how I think of it.</p>
