When to Attack
Being the top ranked player in a castle is not easy, as you are competing with the current overlord as well as everyone else trying to take over the castle. With only 20 challenges daily along with an additional 1 per 30 minutes, you should choose wisely when to attack a castle. I suggest to only buy challenges when neccesary, as they are fairly expensive.
Check the number of guardian stars the current overlord has; if the number is negative, it usually means the castle is easy to attack. A high positive number would mean that you would need a strong team to win the battle.
Check the rankings; if the top player has more guardian stars than you could get out of the 20 challenges (assuming you could win), you should wait until he becomes the overlord of the castle. If the top player under 100 guardian stars, it is a good sign that you could take over the castle. If the top player is the current overlord, remember that you could decrease his guardian stars by winning. When you reach the top, it may be wise to leave a gap between you and the second highest in order to keep your position.
Then, of course, you must make sure you could win against the defending team. If the battles are close, you should go back to headquarters and purchase some boosts. It is a lot cheaper than buying extra challenges to make up for lost battles.
Once you are on the top of the ranking list, others may still try to surpass you. You should leave a reasonable gap (5ish challenges) from the second highest so hopefully they will give up on the castle. You should check the castle before it flips incase someone is planning to take it over last minute.
Build up guardian stars for more bonus stars. Even if you don't get the opportunity to take over a castle, spend the 20 challenges each day in order to accumulate guardian stars; remember that higher level castles will give you more stars.
Defending a Castle:
As mentioned in another section, you must choose whether to try to keep the castle or let it be taken over. If you think you have a strong defensive team, you should purchase bonuses as soon as you take over the castle. Once you realize you cannot hold the castle, it is best to switch to a weak team in order to welcome more challengers to your castle. If everyone wastes their challenges on your castle, it will make it easier for you to take it back later. The drawback of this strategy is it allows people to accumulate guardian stars.