We get a pretty nice overview of Finn's though process from the canon novelisation Star Wars: The Force Awakens - Finn's Story.
He doesn't like killing civilians.
Slip had died for nothing. Even worse, his death had come as they were
terrorizing and killing innocent people. That wasn’t what they had
trained for. The First Order was supposed to represent peace and
stability, not fear and death.
I can’t do this anymore, he thought.
He recognises that having failed to kill the civilians (as ordered), he's in a significant bind, one that results in extensive punishment.
FN-2187’s time was officially up. If he turned over his weapon to Phasma, the scans would show that he had disobeyed orders, and he would be punished. If he didn’t turn over the weapon immediately, she would assume that he had done something to disguise what the rifle would have shown, and he would be punished. If he didn’t show up at Phasma’s division within the next few moments, she would send some of her personal guards after him and he would be punished.
He identifies Poe as someone who can help him to escape both the immediate situation (punishment for not killing unarmed women and children) and the wider problem (that he's working for an organisation that is happy to order him to kill unarmed women and children).
He needed help.
But who would help him?
Everyone on the Star Destroyer was allegiant to the First Order.
Well, FN-2187 thought, not exactly everyone…
FN-2187 took a deep breath as he approached the cell. Once he entered, there would be no turning back. It was now or never. Confidence was key. He kept his stride steady, and the heavy door opened before him.