Interesting, we fixed a bug like this on iOS when iOS 13 came out. I wonder if your keyboard is doing something similar to the iOS 13 keyboard. What phone, OS version, and keyboard software do you use? Does this happen with all keyboards, or just your favorite one?
(I tried on my Pixel 2 / Android 11 with Swiftkey and Gboard in English and Korean, couldn't repro)