I walked into a tree.

Literal

Tree [at-に] collided-[explanatory-んです].

ぶつかる ('to collide with, bump into') takes に to mark what was bumped into — the same pattern as 会う ('meet with'), similar intransitive verbs of contact. The んです ending is the casual contracted explanatory frame, offering the statement as an explanation (perhaps to excuse a bruise or explain lateness).