Or, for simplicity, when all your Pokemon faint. I'm pretty sure it is.
When your Stylus runs out of power, you are transported back to the last save state. The Stylus can be recharged at any Ranger Base
Source: https://en.wikipedia.org/wiki/Pokémon_Ranger
Hope I Helped :)