My guess is he was mortally wounded in an attack at some point, and the Institute found him, stuffed him into a synth replica body, then tweaked his memory of the near-death experience and dropped him back where they found him.
Either that or they straight-up body-snatched him. It's stated that Shaun synth will not age or grow up, so he could not have been a child synth, and since it's set at least 10 years after Fallout 3, and Harkness from Rivet City was a Gen 3 synth, that means they've been able to do that for at least 10 years.
However, the guy from the Commonwealth in F3 who comes looking for Harkness is not Shaun, since, for one, Shaun has never been outside the place until you meet him on the roof, so he's either a rep or he's the previous Father who left Shaun in charge.
There's just too much left unexplained. I've been through tons of dialog - save and reload and pick different options - and you just cannot get a straight answer about anything out of anyone.