I think consuming some portion of your subconscious with repetitive activity frees up some blocking on your conscious thought, so that you can stay engaged on an idea for longer. It's like your normal boredom/frustration loop gets muted by the repetitive behavior (music, movies in background, walking, fidgeting, etc.)
Sometimes having other things going on makes deep work easier, sometimes it makes it harder. I've noticed it's good to test both, and oscillate.