Are you using a specific app when you are experiencing these symptoms?
I would recommend resetting your keyboard settings. Give these steps a try: go to the messages app > tap the text space to open the keyboard > tap the gear on the right side of the keyboard > tap on reset to default settings > tap on reset keyboard settings > tap on reset
Next step would be to test your device in safe mode. If your phone is misbehaving, it's possible that a third-party app is causing the issue. To figure out what app is acting funny, you can use the Safe Mode feature. In Safe Mode, your phone won't run any third-party apps. This allows you to easily identity and remove the app that may be causing the problem. Give this link a try: https://www.samsung.com/us/support/answer/ANS00062983/
I would also recommend wiping the cache partition on your device. The system cache partition stores temporary system data. It's supposed to allow the system to access apps more quickly and efficiently, but sometimes things get cluttered and outdated, so a periodic cache clearing can help make the system run more smoothly. Give these steps a try: