When to castle, when not to castle?


My advice.When the centre is open( both open e or d file), semi open ( either one side of d or e file is open) or dynamic centre ( d and e pawns can be engaged to exchange ). In these three situations , castling ASAP, preferably kingside. When the centre is already closed or potential to close ( d4 e4 on white vs d6 e6 on black, such as sicilian ), wait for castling and push queenside or centre development. If you are already castled and opponent is attacking on your castled king side, open the centre pawns or counter attack on his opposite side. Dont panic if your king is being attack , and dont defend too much. You cann't win by defense on your king but only by faster and effective counter attack.The winner is whoever's faster attack, your counter attack or his king attack.

As said before it depends on the position. But in general your king should be in safety, you have some central control and all your pieces should be active. In most positions the king is more safe on g1/g8 or c1/c8 than on e1/e8. The rooks often belong to a central file and in many positions it is also good when both rooks are connected (no king, queen or minor piece between them). When your opponent exchanges one rook on a open file, you can recapture with the other rook, so the opponents other rook or the queen don't win that file.

‘Great players never castle until the end of the game, and often never at all, as their king, although often in the middle of the board, nevertheless stands secure.’ 😂🤣
‘Good players seldom castle ...’

‘Great players never castle until the end of the game, and often never at all, as their king, although often in the middle of the board, nevertheless stands secure.’ 😂🤣
‘Good players seldom castle ...’
You havent answer his question., and I disagreed your logic, where your logic come from?. Top GMs and top engines like stockfish or komodo also castle even in early opening. ( For example, 1. Ruylopez, for white, 1.e4, 2. Nf3, 3. Bb5 , 4. O-O , etc are fast castling opening) sicilian scheveningen and queen indian defense for black can hold for late castling .

often depends on if the Queens have come of the board. Its more dangerous if the queens are around to stand in the middle of the board
Castling should achieve something of either tactical or strategic purpose, and preferably more than one thing. This can be - (1) Moving the king to safety, (2) activating the rook, (3) connecting your rooks on the back rank, or (4) pressing/supporting an attack on an open/semi-open file.
In general, kingside castling tends to be defensive and positional, so you shouldn't castle kingside if either (a) your kingside pawns have been disrupted, or (b) your opponent has too many active pieces bearing down on that side (as this leaves you vulnerable to sacrifice attacks). A kingside castle should also have at least TWO minor pieces active for its defense, at least until the queens are off the board. Queenside castling, on the other hand tends to be aggressive and tactical, so you shouldn't castle queenside unless you have a tangible plan to use that rook in your attack.
I know strong players who castle early without fail, and others who don't do it until really late or at all (I'm usually in the latter category myself), but those who use the option successfully always have a purpose behind it. Even if castling doesn't make sense immediately, the value of having the option to castle is still important. Hope this helps.

It is suggested from the lessons I've taken here, that you should try to castle before turn 10. Not a hard and fast rule, just a strong suggestion.
Some GM from 100 years ago said "Castle if you should or if you must, but never castle simply because you can".

In general, you want to castle: delaying it can allow your opponent to force delays in attacks you make.
There are cases in which you do or do not want to castle on the opposite side from your opponent: Keres and Kotov, The Art of the Middlegame, Ch.2, “Strategy and Tactics of Attacks on the King” – perhaps the best 50 pages of chess instruction ever written - explains how to decide.
Here's a game where I didn't castle until the 15th move because I was busy pinning my opponent's King in the middle and launching an attack. But when I did castle O-O-O, it was done not to protect my King but to create my d-file Rook, on a file I had just opened up so the Rook would be devastating on the d-file, and it virtually won the game:

The general rule is castle early, but of course that depends on the tactical situation. I have found fairly consistently that the earlier I castle, the more likely I am to win, even if the game goes on to be over 100 moves long. Susan Polgar says that you should castle by the 6th move if you can.

Sometimes your opponent dosen't allow to castle early:
White plays good active chess, the greco-moeller-attack with castling not too early, not to late. Black found the best defence over the time. He must know what to do. E. g. 7... Nxc3 could run into great disaster. There are some traps further on. I once memorized that line up to move 20 when playing 1. e4 e5 with black...

it depends on the positions, no general rules here I´m afraid. But there are some patterns: If you have a Knight on f3-f6 it will be safer to castle kingside, because the knight protects h2-h7 from possible sacrifices, also in general is safer to castle if you haven´t moved your pawns. Unfortunately, there are lots of exceptions to these rules.