Originally posted by Zelnick
Why isn't it allowed?
The straightfoward answer is "that's the rules".
But if you're wondering why the rule was chosen, it's probably because castiling was introduced (just like pawns moving two squares) to provide a short cut way of doing what many players did using multiple moves. i.e. prior to the ability to castle, players artificially castled by letting the rook out and then walking the king over to the side, using several moves to do so. Castling was seen as a pragmatic addition to the rules.
However, such "short cut rules" should never provide new possibilities. If a king was in checkmate prior to the rule, then it should be checkmate with the new rule in place. But this would not always be the case if the king could castle out of check. Hence it's not allowed.
Checkmate before and after the castling rule was introduced.