The advantage of castling is that the king is safer in the corner, where he is sheltered by three pawns and a stalwart knight, than in the center of the board, while the rook is brought toward the center files in the most convenient way possible.
The 10 Most Common Chess Mistakes
Nothing is more important than safeguarding your king by castling early, within the first dozen moves, if possible.
Portable Chess Coach
So, castling is a multi-purpose move, aiding in the development of a strong piece and protecting the king.