click on your castle, you will see 2 options. Hide troops in santuary (which is selected by default), Order troops to defend city. When someone attacks you, if they are in the santuary they will not be at risk, but that will make it easier for people to take your gold and resources if you have no other defences. If you order them to defend the city, then the attacker will have to go through your defences and your troops. It all depends on how far you are in the game. If you have enough storage space for your resources, it will just be your gold at risk.