Charging an iPhone from a closed MacBook I always thought you couldn't charge an iPhone from a closed macbook without opening it first, and then closing it after plugging the iPhone in. However today my phone was completely dead and I was on a train unable to take my laptop out and open it even a little bit.

the phone charged while it was dead, and when it turned on it was on 2%, however it didn't stay charging, instead 5 minutes later it died again, and starting charging while dead again. 

Is there a way to keep the phone charging after it turns on from dead? (without opening the macbook, it seems like it's the phones fault it stops charging as that's the only thing that doesn't change, and it's jailbroken so I can install tweaks)
You would want to enable closed clamshell mode (search Apple.com/support) for the details on what is required on which models:


Attached external display
Connected USB device like keyboard or mouse 
Connected to power charger and not running on battery


At this point, you'll get the normal USB charging or the enhanced charge if the hardware detects your iOS device as benefitting from the capabilities of the hardware to charge at a higher rate than 500mA.

If you cannot run in closed clamshell mode, set the sleep to be long enough to get a charge and prevent the lid from closing completely. Setting up power nap will also allow brief moments of charge, but that isn't intended to get a realistic charge over USB.