It happens just after a thread or page loads. Like the ads sometimes take a few seconds to load in. The warning then appears. When I click "Take me back to safety" it takes me back to the previous page.
So e.g.
Reading this thread
Click on Threads I'm on - loads - warning comes up (have definitely not clicked on page accidentally or otherwise)
Click "go back to safety"
Takes me back to this thread (not I'm on).
I don't think it's a redirect, I think it's picking up on a dodgy element of an ad within the page