The keep in a castle acts as the "final goal" for armies attacking you and trying to attack your village. If someone is trying to raze your village they have to reach the inside of your keep at which point you lose your village. When AI opponents attack, if they reach the inside of your keep it will cost you honour, but they will not raze your village.
To get a flag from attacking a parish capital you must enter the keep.
The Keep as a weapon
The keep when upgraded to Level 10 is a formidable defence with rapidly firing towers that can mow down enemy troops. It can deal with small armies by itself but when over whelmed by a large force it will not kill enemy troops quick enough before they reach the inside of your keep. Combining its fast firing rate with archers, ballista towers and turrets provides a very big defence against enemy armies.
As soon as enemy troops cross the white line surrounding your castle the keep will start firing. Its most effective when you have large towers and moats around your castle because it will fire on the troops stuck there trying to dig up your moats or knock down your walls.
The keep cannot be destroyed by either enemy catapults or enemy troops, it will always remain. You can place 6 or 7 troops inside the keep. The best defence you can have to slow down enemies sending large waves at you is to keep a number of captains inside the keep because of their hit points and strength. Because the area leading into the keep is only 1 tile wide, it means that if you fill the inside with troops only 1 enemy troop can enter at a time and this cause the enemy army to "jam" outside of it. Even keeping a small number of troops inside the keep means they can slow down the enemy greatly while your archers fire and kill the troops stuck outside of it.