Castles are formations of pieces that surround and defend your king. Unlike chess, where the only "castle" is putting your rook in front of your king, Shogi castles are deliberately designed to ward off the opponent's attacks and keep your king as far away from the battlefield as possible. There are many types of castles and many variations of every kind of castle, but here are the three most common castles:
Yagura CastleYagura Castle is one of the most popular kinds of castles, although it takes some time to make. It is used when the opponent is playing Static Rook (when a player keeps his or her rook on its opening file in the opening). Its strength is that it heavily defends the front of the king, which is where a Static Rook player will be opening fire. Often times you will see two players in Yagura Castle at the same time, as they are castled used by Static Rook players. Its weaknesses are the left side and the bottom.
Mino CastleMino Castle is another popular castle, especially among beginners, especially because it is one of the easiest castles to make. Mino Castle is used by Ranging Rook (when a player moves his or her rook in the opening) players, typically against Static Rook players, because it heavily defends the left side. Its weakness is the silver general's head, 3g. Often times the rightmost pawn will also be pushed, to give an escape route to the king.
Anaguma CastleAnaguma Castle is a fairly popular castle among beginners because it is one of the hardest castles to break in shogi. It defends decently from the front and heavily from the side. The biggest problem with Anaguma is that if your opponent manages to break your castle, you will be checkmated in a few turns because your king has no escape route.
Now that I've given a quick introduction to castles, I'd like to go into their uses in-game. A few months ago when I was very new at shogi, I was of the mentality that, "Well if I can make a big enough attack, they won't have time to attack me, so I don't need to build a castle." This mentality worked against some of my friends and some other beginners in PlayOK, but as I started getting better and playing against better players, I realized I was very, very wrong. It's always important to protect your king in one way or another. There are two shogi proverbs that apply to castling: "Avoid a sitting king," and "Protect your king with three generals, etc."
Here's an example of one of my games that I just played tonight where I had a solid defense while my opponent didn't:
hirohiigo (black) vs. mawelikeke (white)
I knew for sure that I was going to win this game at move 36. S-2f. He made a huge error in making that move, and it allowed me to play 37. Rx2f. He hurried the game along by playing 39. B-2e to attack my rook. Since I could skip going after his bishop, I could run straight into his camp and promote. With a dragon and 2 generals in hand in that kind of situation, I don't think it's possible to lose.
Mawelikeke could have extended the game even farther, but by playing 42. R-5a, he put himself in a Mate In 2 situation, and he could not block 43. +R-4c. 44. K-3a 45. R*3b Gold on the Head checkmate. Mawelikeke was obviously new to the game, so I don't blame him for not knowing any castles. But my next example is against a more skillful opponent:
ryoku (black) vs. hirohiigo (white)
Ryoku showed his aggressive intentions right away by opening with a one move loss bishop exchange and quickly moving into a third file rook strategy. His attacks were coming so fast that I was having trouble keeping up with him - it was like he had his attack planned out before the game even began. I was panicking early into the game, but his first major blunder followed my bishop promotion at 16. Bx6g+, in which his reaction was 17. Px7c+. I don't understand why anyone would continue their attack with a major piece in their camp. Whatever the case, he traded a rook and a pawn for a bishop and a pawn.
But even after that his attacks were coming in strong. The only thing I could do to save myself from 23. R*7a was R*6a to force a rook trade. It kept going on like that until I managed to kick his horse off of its diagonal with 42. B*7b. As soon as his horse moved, I began preparing for my attack with 44. R*7d. He delayed my attack slightly with his lance and knight drop, but the moment I was able to make my first check with 54. G*6i, his entire game collapsed and I won. In the end, it was a matter of the player who had the stronger castle survived.
I hope these real examples of the benefit of castles has taught any beginners reading this how important it is to castle your king, or at the very least move him away from 5a (or 5i if you're black) into a more secure position.