If you are locked out, then your only option is erase the iPhone from iCloud or force-restore the iPhone to factory settings through iTunes on your computer by putting it to DFU (Device Firmware Upgrade) mode, which will erase everything from it. This is how Apple designed it to protect the information of their users. (Note : DFU Mode is a method which allow you to bypass the passcode screen and get it restored)
But if you had backed up your iPhone to iTunes on your computer or iCloud, then you can restore all your data back after restoring your iPhone from iTunes/iCloud. You can also redownload all your past purchases for free using the same account.
Following are the two methods to fix it
Method 1 : Erase from iCloud
If you have iCloud enabled on it and also if your iPhone is connected to WiFi/internet, then you can do the erase (restore) from iCloud - so you don't have to go through the restore steps.
On your computer, go to www.icloud.com
Login to your iCloud/Apple account. Click Find iPhone. Select your iPhone under All Devices. Click Erase button and it will be erased (if it is connected to WiFi network). This will erase and restore your iPhone . After that, setup your iPhone. Select Restore from iCloud backup while setting up.
If this didn't work, then please do the Method 2 following below;
Method 2 : Fix it using iTunes on your computer by putting the phone to recovery/DFU mode
Follow the steps below to restore your iPhone by putting it to DFU Mode.
First download and install latest iTunes on your computer from here : https://www.apple.com/itunes/download/
Then connect the iPhone to your computer with the USB Cable.
Open iTunes application on your computer.
On your iPhone press and hold the Home button and the Power button at the same time.
After EXACTLY 8seconds release the Power button. Continue holding the home button until your iTunes shows a message telling you that it has detected an iPhone in recovery mode.
Click OK or Restore
Note : Put it to DFU Mode while connected to computer and also in DFU Mode your iPhone will remain blank and will be unresponsive. It is normal. If it is not showing blank/black screen, then repeat the steps again. Timing is critical when you put it to DFU Mode. So keep trying until it goes to DFU Mode. And it will take a while to restore it.
Remember, it may take a while to restore the iPhone (the iOS firmware has to be downloaded, you will see the Download button - a downward arrow button with spinning circle around it, at the top right corner of iTunes screen. Click it to see the time remaining)
Please let me know if that didn't work, so I will continue to help you until we fix the problem