It is normally good to castle to keep your king safe early on in the game. Even when castled it is imprtant to keep enough pieces near your king to defend against attacks. Your opponent may build up pieces near your king or sacrifce a piece for one of the pawns in front of your king to give it less cover.
The Greek gift sacrifice shows what happens when a castled king is not defended well enough. It always starts with Bxh7+ (or Bxh2+ if black is attacking). Just like taking the Trojan Horse from the Greeks, taking the bishop often spells disaster. Here’s an example.
If there is a bishop defending g5, the attack can be strengthened with a pawn on h4, especially if white’s rook is still on h1.
One more example, this time from ex-world champion Emanuel Lasker. In this case the the knight does not come to g5 but Lasker suceeds with a second bishop sacrifice.