After a player castle, he gets his king into a safer location. Look at the following example.
Both White and Black had performed the castling. But, if in this position, the king is attacked by a rook or the queen and the disadvantaged player has no possibility of capturing the attacking piece or has no possibility of interposing a piece between the king and that rook or queen, then checkmate results (because the king has no where to go). This type of checkmate is sometimes called back rank mate ,because it takes place on the back rank.
In the following example the white king is exposed to being checkmated on the back-rank with 1... Re7-e1. The black king is, however, quite safe because of the escape square at h7 ; so if White has its turn to move and tries 1. Rd3-d8 then the king can escape with 1... Kg8-h7.
In the following game Black is down a rook. But if you look more closer you can see that White is predisposed to being checkmated on the back rank: 1... Re7:e1 2. Rc1:e1 Qb4:e1 Checkmate!. And even if the Black had a rook less he won the game.
In the next example the black king has the escape square at h7 but that square is under the control of the white bishop from d3. So after 1. Re1-e8 the king is checkmated.
The fact is that many tactics
revolves around back rank mate. Many beginners often fall in this kind of
traps.
My advice to you is to pay attention
when you run into this kind of positions. It's always a good idea to have
an escape square where the king could move if attacked, or some other way
to protect it.