I have a jailbroken iPhone which is set up to retrieve mail every 30 minutes.
Is there a way I can prevent this from happening at 3am when I'm trying to sleep?
It does not look like there is that level of configuration granularity on iOS for the iPhone out of the box (non-jailbroken).
One of the common jailbroken apps; 'SBSettings' also don't seem to have a specific setting option for scheduling push times...
One option might be, if you don't want to be disturbed at all is to switch to "Airplane Mode" before you go to sleep. But note this will prevent receiving calls and text messages also.
Or simply turn off "fetch data" (or set it to "manually") before you go to sleep.
Settings > Mail, Contacts, Calendars > Fetch New Data > Push = Off | Fetch = "Manually"