This is probably one of those things that varies a lot based on what your field is and how close to academia you stay while in industry. It's going to be a lot harder to come back to doing experimental physics if you spent 5 years as a software engineer.
Right but someone who has a realistic chance at being hired as a professor won't be working as a commodity software engineer, they'll be in some sort of specialist/research role. Any of the job offers I've seriously considered leaving were to be a computer scientist.
Just one example: My PhD advisor went directly to industry after their PhD, stayed there for 10 years, and then went back to academia. Six years later they had tenure. "I got lucky" was frequently said, though.
I did it. I went straight from my PhD to industry (actually my own startup) and then 5 years later I went into academia and tenure. I left academia in 2012 back to industry. This is the biological sciences (Molecular Biology / Microbiology).
I should say I am the only person I have ever met in the biological sciences that has done this so it must be relatively rare.
I know that at Texas, in engineering (where I got my PhD) we had many, many professors with previous industry experience. I remembered thinking it was not nearly as terminal a decision as I had expected.