If you are technical enough you can use an Xposed module to prevent that. Like one that reduces the intake of energy while charging. Some ROMs also offer that built-in.
Try to see what your charger is. Maybe your phone is using "fast charging" which might make it charge faster but it will definitely get hotter. A charger that is compatible with your phone and without fast-charging capabilities might help your phone not be as hot.
Lastly, and this is less about the energy part and more about safety, make sure if you charge it unatended that it is away from anything flammable. While there is a very small change something like that would ever happen I wouldn't take the risk.
Something I forgot, if you are brave enough, replace the thermal paste with a good quality one. Recently I did it and since then I have seen a huge difference. Just make sure to disassemble everything so you can access the CPU and the radiator.