@ayushsharm74959 since this happens when it is on charging, it is possible that this is either a bad battery or a bad charging port. I would go ahead and replace the battery and check the charging board. I would most likely replace that as well, since the cost is not high and schematics for it, are not available.
Since iFixit does not yet have specific guides for this, use something like [https://www.youtube.com/watch?v=Wka3waJpsHo|this video] Replacement parts are readily available at many online stores.
While you work on your phone, take lots of pictures. Once you are done with it, take those pictures and create a guide for iFixit. That will help the next person that has a device with the same issues as you do. It's easy and fun to create these guides. https://ifixit.com/Guide/new The iFixit community will appreciate this.
Repair is War on Entropy!