What OS? I've never had my mac go to sleep in the middle of handbrake. That is odd but I use a desktop. If you have scheduling assistant set up to sleep at a certain time, I believe that overrides everything else.
If you put your computer to sleep, it will (as the word "sleep" suggests) pause all current apps running. If you want to run something overnight, go into System Preferences -> Energy Saver and change it to never go to sleep when plugged in (display sleep is ok, but not computer sleep). Also, don't close the lid when you leave it, as that automatically sleeps your computer.