I have contemplated this mystery, and here’s my take for what it’s worth:
When I was a kid, our parents took the six of us to vacation in Washington. We went to the Smithsonian, and somehow my little sister got separated from us and became lost. We wandered around for some time looking for her, and then were paged and a guard delivered her while she was blubbering, “I lost my mommy.” In large crowds, kids can get lost, and as I see the pilgrimage it was like that. Perhaps Joseph, walking with the men, thought Jesus was with Mary and conversely Mary thought him with Joseph. I think we can understand how this happens. Somewhere down the road, perhaps to rest, eat or turn in for the night, all the pieces come together and they realize he is not with them.
What to do? They can only head back to the city and look for him. Had they walked a day before noticing? Did they take a day returning? And a day searching? I mean we are talking Jerusalem, not some small village in the sticks (Nazareth). Now I think that is what they did, and after some search, maybe as a last resort, they thought to go to the temple. To pray? To ask for advice? In desperation? And what under the circumstances could Jesus do. Jesus, knowing his parents, concludes that he will go somewhere they will surely go to look for him. And there he was, not only there, but spending the time discussing God. I could see them all very emotionally reuniting, and Jesus explaining in the way of a twelve year old, “Where on earth else did you think I’d be?”
Finally, in meditating on it, I considered it very possible Mary herself was the source of this Gospel account, since she would know these details of Our Lord’s life and who else? And then I began to think of Mary as the fountain from which the Gospels spring. At least that’s my meditation on it.