IIRC it as invented to get the rooks out on the board quicker. Normally, it takes like four moves to properly get them out there (1. move pawn out of the way, 2. move rook ahead, 3. slip rook out through the side, 4. move rook onto the board.) With castling you can greatly reduce this if you've opened up the middle already.