Well, in some fanfictions, it could be due to a new jutsu he discovers accidentally. Maybe during a really intense training session in a mysterious place, he unlocks this strange power.
Another possibility is that it has something to do with his connection to the Nine - Tails. Since the Nine - Tails is such a powerful and otherworldly force within him, some sort of energy transfer or mutation might occur that gives Naruto the ability to phase through objects. This could be related to the Nine - Tails' own nature of being able to exist in a different dimension or state at times.
It might be the result of a curse or a blessing from some ancient entity. For example, he could have come across an old shrine in a forest and unknowingly received this power as a form of protection or test from a long - forgotten spirit.