He just really, really wanted a pill.
It's easy to forget that the Jack we saw in "Through the Looking Glass, Part 2" was Jack less than a week earlier. He spent all of seasons 5 and 6 suffering serious withdrawal. This explains some of his irrational behavior and his many jackfaces. It also may have created the flash sideways. It also explains how he survived the Heart's electromagnetism.