overnight in JFK

I wouldn’t take the risk, changing terminal adds extra time, and you never know about any immigration delay. Some times the passengers are out within an hour, and some times it takes upto two hours. and remember, you would need to go through security again to board your next flight. Evening time is a pretty bz time at the airport.