OK, I don't know how you could 'shut off the keyboard' other than uninstalling it - you can deselect additional keyboards, but I don't think it will let you do that for the system one. Of course if you uninstalled the system one after installing one of your own you might manage this - if that's the case then a factory reset will not make things easier, as that will leave you with no keyboard at all. But I'll assume that you mean that for whatever reason it won't give you a keyboard to enter your PIN or password. Please correct me if that's wrong. And if you have any information at all about what happened before this problem started, please also tell us that - we only know what you tell us, so the more information the better.
<br>
<br> So, since you have TWRP installed, are you using a custom ROM? If you have accidentally uninstalled the keyboard you could just reflash the ROM (without doing a reset if it's the same ROM) and that will fix it.
<br>
<br> Assuming that you still have the stock ROM, a simple thing to do is go into TWRP and delete the cache and dalvik/art. This is harmless: it will just mean that your next boot is longer as the dalvik or art cache is rebuilt, but if it's a glitch with the installed app or due to bad data being cached there is a chance this will fix it, and at worst it wastes a few minutes.
<br>
<br> If the phone boots up with an internet connection you could try installing a keyboard by pushing from the Play Store (from a web browser). But I suspect you'll have to enable it before it can be used, which will require getting past the lockscreen.
<br>
<br> If your keyboard has been uninstalled you could also try to install an apk using ADB - that won't work when running Android unless you can unlock, but you should be able to use ADB while in TWRP.
<br>
<br> It's also not clear whether it's actually the system keyboard app that's the problem. I've replaced and even removed system keyboard apps and I'm fairly sure the keypad in the lockscreen (which is I think your problem) doesn't change with the keyboard app (but not 100% sure, as it's been a while). If you've a USB OTG adapter you could see whether you could use a USB keyboard or mouse to unlock it, but if they keypad/keyboard isn't appearing on screen I don't think that will help.
<br>
<br> With a bit more description of the problem we could probably come up with something else.
<br>
<br> If you have used TWRP to make a backup then you could restore that - that will of course reset your phone to exactly the state it was in when you made the backup, so you could lose stuff like more recent messages, game progress or whatever. If you think the problem is in the ROM rather than the data you could do a selective restore, just restoring System but not Data (which would reinstall the system keyboard app but would not overwrite your messages etc).
<br>
<br> If the worst comes to the worst, nothing else works and you don't have an existing backup, use TWRP to make one before doing a factory reset. That way you've at least got a copy of your apps, data and current ROM. If you do that then the paid version of Titanium Backup can extract user apps and data from a TWRP backup, so you should be able to restore a lot of stuff that way (I don't think it will restore system data that way - you don't want to do that when changing ROMs, so I'd expect them not to include that option). This would be my last resort, but it's a possibility.