Shot in the dark, so to speak...
Reading from the comments its wasn't a "camera" it was an iPhone (authors says in one comment: "I've been researching about iPhone Portrait mode glitches for days but haven't found any info"), so some heavy automated post-processing can be assumed.
Given that the picture is taken with the sun in the background, the iPhone software is doing whatever it can to fix things, and it possibly took several shots with different EV settings to blend them (you'll notice that the blend only applies to the darker parts the ghost: hair and cap).
So we can wonder if between some of these shots, the ghost in the background disappeared behind the main subject, so some blending happens between a shot where the ghost is present and the one where it's not.
Only the developers of the Apple camera software will know...