Be careful when doing this. If left unchecked this could very easily start a fire. I did this with an old Nexus 5 and it only took a couple of days before I had a spicy pillow.
Although, this probably works well for a device with a removable battery and that can be powered by USB alone.
If the hardware and software are designed and tested for it, then yes.
Otherwise you may run into various issues caused by phone self-limiting power it takes from USB port. Some kind of negotiation needs to happen before the phone can safely raise the input power limits. If it needs more than currently allowed, it will just poweroff immediately, instead of satisfying the excess need from the battery.
Or a timer switch. Christmas lights 6 hours on 18 off power timer switch. Or a smart switch. Also make sure there is no cushy things like pillow or clothes or stuff around phone.
Although, this probably works well for a device with a removable battery and that can be powered by USB alone.