The same way you use stealth rocks or any other non damaging moves, only when you're facing a Pokemon that yours should force out or when the opposing Pokemon can't put a scratch or cripple yours. There was a question about when to use setup moves but I'm too lazy to find it but the same principles apply
Another perfect time to use substitute is against Pokemon that you are like 99% sure will use a status move like toxic and will o wisp. This is probably the single best time to use substitute since the status move will fail and on the next turn, either your opponent switches or has to break the decoy. Either way, you're Pokemon gets the free boost and it could be a free real estate, depending on who the boosting Pokemon is
When you use substitute, you're goal is not to keep the decoy alive but merely to boost up to be able to man fight or outright defeat your checks and counters, or even just to inflict significant damage on them as they break the decoy so you can safely bring in your own check