Most of the time, castling is pretty good. But there are certainly times where other things take priority (for example, maybe you find it worth winning material at the cost of being able to castle). In this case, black's pieces were cramped and had a hard time getting to you, so, since you were winning that important d5 pawn, it was probably worth giving up castling rights. Usually when the game is more open you don't want your king to be a liability, which will distract you from connecting the rooks and coordinating all of your pieces.
Another way to put it: When you're in control, usually a slightly exposed king will be hard for the opponent to exploit; if you're under pressure, then an open king will make it all the more easy for him to hurt you.
Don't look like it in this game I played as white.