It was answered by the Serena A.I. (Skynet) herself:
Dr. Serena Kogan: Welcome home, Marcus. We knew you'd be back. After all, it was programmed in you. Oh, and you executed that
programming beautifully.
Marcus Wright: What am I?
Dr. Serena Kogan: You are an infiltration prototype. The only one of your kind. Advanced Cyberdyne's work, we resurrected you, amended
it.
Marcus Wright: You're dead.
Dr. Serena Kogan: Calculations confirm Serena Kogan is the
[transforms into John Connor]
John Connor: easiest for you to process. We can [transforms into Kyle Reese]
Kyle Reese: be others if you like. Marcus, what else could you be... if not machine? [transforms back into Serena Kogan]
Marcus Wright: A man.
Dr. Serena Kogan: The human condition no longer applies to you. Accept what you already know. That you were made to serve a purpose.
To achieve what no other machine has been able to do. To infiltrate,
find a target and then bring that target home to us.
[flashback recording from Marcus' perspective]
John Connor: We've been at war since before either of us even existed. You tried to kill my mother, Sarah Connor.
Dr. Serena Kogan: In times of desperation,
people will believe what they want to believe. And so, we gave them
what they wanted to believe. A trick in the form of signal the
Resistance thought would win the war. And they were right, it will end
this war. Except that it is the Resistance that will be destroyed.
Not, Skynet. Our best machines have failed time again to complete a
mission. Something was missing. We had to think, radically. And so we
made you. We created the perfect infiltration unit. You, Marcus. You
did what Skynet has failed to do for so many years. You killed John
Connor. Don't fight, Marcus. Remember what you are.
Marcus Wright: I know what I am.
[rips out computer chip, crumbles]
Marcus Wright: I'm better this way.
Dr. Serena Kogan: You will not be given a second chance. You cannot save John Connor.
Marcus Wright: Watch me. - IMDb
He was programmed that way to believe that he is human bu to also achieve his mission which he did. It was his will power that he reversed his mistake later.