You can only retreat once per turn. Other effects that switch pokemon, such as Solgaleo GX, Keldeo EX, and Zoroark, do not count as retreat, and can be used as much as the ability/effect allows.
Also to add on to what @Frosstoise said, in addition to abilities, cards like Switch and Escape Rope can switch out your active without using your once-per-turn retreat. The extra abilities and cards can usually bypass things like asleep and paralyze, or an effect of the opponent's attack preventing retreating.