When is castling needed? I am a rookie in chess. I can't understand why castling is needed. 

In what scenarios is castling useful?
Castling is extremely useful in almost all games.  It lets you do two things at once.  First, it moves your king from the center to the side of the board, where it is much more difficult to attack for the opponent.  Second, it brings one of your rooks towards the center of the board, and it crucial in bringing both of your rook into the game.

There may be a number of potential reasons why these points might not make sense to you. Here is an (incomplete) list:

a) you do not feel that the king is in danger in the center

b) you feel that the danger on the side of the board is the same

c) you feel that activating the rook is not too useful

For a) you should probably have a look at how to attack if the king stays in the center; develop, try to rip open the center e.g., by advancing (even at the cost of sacrificing) some pawns in the center.  Once you find out how to do this and also experience how it feels being torn apart by such an attack, you will appreciate being able to quickly move the king out of the center.

For b) it is important to understand that, generally, the initial pawn positions on the 2nd/7th rank are the most resistant.  It might be that you unnecessarily weaken the protection of your king by pawn moves here.  Also you should have a look at some standard motifs, such as the classic bishop sacrifice (google the keyword).  Avoid such configurations and do not push the pawns in front of your king too much and you will soon realize that the side of the board is a much safer place to be.

Finally, concerning c), it is a sad truth that many players do not use all or even most of their pieces.  Having a rook stuck in a corner essentially amounts to having a piece less; for attack and for defense.  You should strive to activate all your pieces and also to connect the rooks, possibly even double them on an open file.  For this, castling is the single most effective means.  All other ways to activating and connecting the rooks likely take both more moves and require additional, potentially weakening, pawn moves.