Upvote:3
In order to go between terminals 5 and 4, you'll have to take the AirTrain which means leaving the post-security area. That said, 2 hours should be more than enough time to leave your gate, take the train, and go through security and catch your second flight. I wouldn't be concerned unless your flight gets delayed.
Disclaimer: I've not been through JFK too many times so it may get more crowded than I've seen it.