The very specific rule is this: when you are required to interact with the top card of your deck, and your deck has no cards, you immediately reshuffle. This may or may not be on your turn. Interacting with that card includes:
Drawing cards at any time, including someone else's turn (e.g. Council Room, Minion)
Revealing your top card (e.g. Spy, Oracle)
Examining your top card (e.g. Cartographer, Navigator)
It does not include putting something back on top of your deck (e.g. Lookout, Ghost Ship). Doing that requires no interaction with the top card.
Note that this refers to the top card at any time. If you're to draw three cards and there are two in your deck, you draw those two, attempt to interact with the top card of your deck (which no longer exists), reshuffle, and draw the third card from the top of the shuffled deck.
In face-to-face play, it's not uncommon to pre-shuffle if you know you will be needing to reshuffle on your next turn... just don't turn the discard pile into the draw pile until you actually have to do so.