<Snipped quote by Ace of Hearts>
That was part of his development. This was a guy who had to be king -- didn't want it, didn't ask for it, it was his duty. He gave everything he cared about because that was his duty, and it broke him and everybody around him.
This.
There are three conflicting threads in Stannis's personality;
1: That he is legalistic and thinks everything that has gone wrong is because others broke the law by refusing him. This means he is duty bound to do what will restore the rule of law.
2: From his perspective, the only higher power that has helped him in any way is the R'hllor. This is better presented in the books, but it is still present in the show. That power restored control of the Baratheon faction to him, helped to weed out the competition via leech magic, and supported his biggest victory north of the wall.
3: His natural duties to his daughter, both as her father and as a lord raising his heir.
I don't think it is too surprising that, considering how each of these have played out in his life during the timeline of the shows, the second one ends up winning his personality when the chips were down. It was a brutal scene, but it followed from everything leading up to it.
The place they dropped the ball was on that last battle. They shouldn't have tried to cram all of that into the last episode. Stannis in front of the wall and Sansa hopping out the window, that could have waited until the beginning of this season to do all that. But ending that plotline on an off-screen battle followed by an offscreen death? Yeh, they fucked up royally there.