I love this phenomenon. I'm sure there's a better terminology for it than my ramblings, but I see it everywhere, it goes beyond foreshadowing and into things like subtext, and I don't think it's necessarily accidental.
A very common example you see in online spaces are trans folks drawing themselves as the opposite sex long before the realize years after the fact that that might mean something.
Hayao Miyazaki has the most chaotic way of making films that I've ever seen. He has no idea how the story is going to end when production starts. In Spirited Away he described the flooding at the end as a fortunate accident. He wanted the train scene to be completely barren in contrast to all the previous visual noise, and was relieved when he realized he had foreshadowed it.
There's a fun interview with spielburg about close encounters of the third kind where he's confronted with the interpretation that the movie ends with music and computer science coming together which were the respective professions of his parents, so it was a scene about him reaching out to communicate with his parents, and he laughs because he didn't realize that when he made it.
Edward Bulwer-Lytton said “Talent does what it can: Genius does what it must.” and I think that describes this perfectly. You know what a 4 act structure is in basic terms, and there's nothing particularly superhuman about recreating that formula, but there's this small but significant part of you that, unbeknownst to you, is intentionally calling shots and turning that work into something more than you intended.
You could call it accidental, but you did it. Another good quote from red letter media: "You may not have noticed, but your brain did."