Credits to makeusof!
Perform a Factory Reset From Recovery Mode
If your Android device appears to power on and boot up normally, but a problem occurs — maybe the boot process fails, the device freezes, or it immediately reboots or shuts off — there may be a problem with your device’s software. In this case, long-pressing its power button or charging it won’t help. These methods only help you fix a device that won’t respond at all.
There’s a hidden way to perform a factory reset of your Android device when it isn’t booting properly. Note that this will erase the contents of your Android device, resetting it back to its default state. This method should only be used in a worst case scenario when your device is unusable due to crashing or freezing software, as you’ll lose everything that isn’t synced to online services.
First, you’ll need to access your device’s recovery mode. Turn the device off completely, then boot it up with one of the following button combinations:
Hold Volume Up + Volume Down + Power.
Hold Volume Up + Home + Power.
Hold Home + Power.
Hold Volume Up + Camera.
This will vary from device to device. If none of these combinations work, try performing a Google search with the name of your device and “recovery mode” to find the correct key combination for your device.
The device will boot to a screen with an Android and an open chest panel if you’re successful. Press the Volume Up and Volume Down buttons until the Recovery mode option appears on the screen. Press the Power button and your device will reboot into recovery mode.
Hold Power and tap Volume Up. Select the wipe data/factory reset option with the Volume Up and Volume Down keys and tap Power. Select the Yes option and tap Power to continue.