Losing cities is part of the game and you gain experience points when your and the enemy’s soldiers are defeated or when you lose cities. This allows you to invest into attacking other cities starting from your main city which you can never lose.
You can plan ahead by making sure you can defend all the cities you capture or investing in skills that reward you the more cities and troops you lose.