In general, it's a good idea to castle early in the game, as your king will usually be safer after castling. (Questions: 1. Why is the king safer after castling? 2. Which is safer, kingside castling or queenside castling?)
But there is one mating formation that is much easier to execute against the castled king: that's the back-rank mate.
White has just delivered checkmate on the back rank with Ra1-a8
Black's three pawns protect him well against frontal attack, but they also suffocate Mr. King, denying him escape from the first rank.
How can you, the alert defender, stop back rank mates? You can create an air hole for your castled king in the pawn formation. And in fact, the chess term for such a move is "Luft," from the German word for "air" (to remember the word, think of "Luftwaffe" or "Lufthansa"--it's pronounced something like "looft")
Black to play is OK: he has Luft on h7
P.S. Here's a nice introductory video on back rank mates at chessdryad.com.