You get trophies by successfully raiding other player’s islands and by defending your island from other player’s raids successfully.
However, you lose trophies when other players raid your island successfully.
You can see the trophy meter while you are raiding at the top of the screen and as long as it is in the green you will be gaining trophies from the current raid.
In order to climb in the leaderboard rankings, you need to obtain trophies by winning raids and defending your islands against other raiders, by building a strong base.