haha, i happend to read about a passage about how to sign in Windows 10 in a Dell laptop when forgetting its password. Share it with you. Hope to be useful. https://www.isunshare.com/windows-10-password/forgot-dell-xps-laptop-windows-10-password.html
Well, i just have the same experience with you. forgetting the passcode of a iDevice, but my iDevice is an iPad. But i think maybe the way to solve the problem is similiar, so i recommend you to refer to https://www.isunshare.com/iphone-ipad/remove-passcode-from-ipad-if-forgot-it.html. Hope to be helpful.
Well, this is a common issue after restoring to factory default. You can use a third party tool to help to enter the safe mode of iPhone 5 and then just repair this problem. Just refer to How to Get iPhone/iPad/iPod in or out of Recovery Mode with iOSBoot Genius