Plot summary
Shaw is seen undergoing surgery by Samaritan operatives to have an electronic microchip implanted between her ear and her brain stem. She is able to turn the tables on them by breaking out of confinement and finding the team. Together, they trick Samaritan's operatives and capture Greer. With Greer in captivity, Shaw removes a USB drive embedded inside his arm which Finch is able to analyze, discovering it to be a kill-switch for Samaritan. Shaw had revealed to Root that she was subjected to extreme psychological torture while captive; once Greer starts to taunt her about the kill-switch and her mental state, she hallucinates heavily, loses control of reality, and kills him.
Shaw continues into a neurological downward spiral, causing her to kill Reese. She is about to kill Root when she confesses that Root was her only mental safe-place and turns the gun on herself. The narrative returns to the operating room and it is revealed that these events happened only in Shaw's mind. She has been subjected to thousands of electrochemical simulations by Samaritan so its operatives could see if she would lead them to the Machine and its assets. This particular simulation was number 6,741.
Credits
Adapted from Wikipedia contributors, Person of Interest season 5. HTML formatting and reference markers removed.