Because I keep wanting to post this every time I see this question, and it's a valid partial match, Philip K. Dick's "The Electric Ant" matches on a man learning that he's a robot.
Garson Poole wakes up after a flying-car-crash to find that he is missing a hand. He then finds out that he is an 'electric ant' – an "organic" robot. He further finds out that what he believes is his subjective reality is being fed to him from a micro-punched tape in his chest cavity. He experiments on this tape by adding new holes, which adds things to his reality. Convinced that his entire reality is constrained by the tape, he makes a major change to it, with a major effect on his reality. The change affects everyone else he interacts with, which raises the question of whether any of them – or he himself – are "real" at all.
However, it does not end with them reprogramming. Rather, when he arranges for his tape (which has holes cut into it that account for things in his reality) to run out, he experiences everything at once from his perspective, followed by:
Frozen against the wall, Sarah Benton opened her eyes
and saw the curl of smoke ascending from Poole’s half-
opened mouth. Then the roby sank down, knelt on elbows
and knees, then slowly spread out in a broken, crumpled
heap. She knew without examining it that it had “died.”
Poole did it to itself, she realized. And it couldn’t feel
pain; it said so itself. Or at least not very much pain;
maybe a little. Anyhow, now it is over.
I had better call Mr. Danceman and tell him what’s
happened, she decided. Still shaky, she made her way
across the room to the fone; picking it up, she dialed from
memory.
It thought I was a stimulus-factor on its reality tape,
she said to herself. So it thought I would die when it
“died.” How strange, she thought. Why did it imagine that?
It had never been plugged into the real world; it had
“lived” in an electronic world of its own. How bizarre.
“Mr. Danceman,” she said, when the circuit to his
office had been put through. “Poole is gone. It destroyed
itself right in front of my eyes. You’d better come over.”
“So we’re finally free of it.”
“Yes, won’t it be nice?”
Danceman said, “I’ll send a couple of men over from
the shop.” He saw past her, made out the sight of Poole
lying by the kitchen table. “You go home and rest,” he
instructed Sarah. “You must be worn out by all this.”
“Yes,” she said. “Thank you, Mr. Danceman.” She
hung up and stood, aimlessly.
And then she noticed something.
My hands, she thought. She held them up. Why is it
I can see through them?
The walls of the room, too, had become ill-defined.
Trembling, she walked back to the inert roby, stood
by it, not knowing what to do. Through her legs the carpet
showed, and then the carpet became dim, and she saw,
through it, further layers of disintegrating matter beyond.
Maybe if I can fuse the tape-ends back together, she
thought. But she did not know how. And already Poole
had become vague.
The wind of early morning blew about her. She did
not feel it; she had begun, now, to cease to feel.
The winds blew on.