Agree with this. A few little things I want to add:
* In addition to times where you have momentum, you can use set-up moves to punish passivity. There are some defensive Pokemon, like Toxapex and Mandibuzz in OU, that really lack an offensive presence. If you can afford getting poisoned, you can set up to power through them.
* The best time to set-up is when your opponent's Pokemon has no way of KOing the Pokemon you're about to switch in, and they have nothing left that could outspeed and/or tank its attacks. This is your 'win condition' and what you're trying to set up in the mid-game. Sweeps are easier if you plan them.
* Always assess risk vs. reward, both for you and your opponent. As the answer leads on, there are quite a few times when you should willingly stay in against a Pokemon that could KO, simply because you can't afford your opponent potentially setting up while you switch. Don't take the risk, and expect opponents to think similarly.