Yeah this bug is driving me nuts sometimes.
I've reported it here The Rich Text Editor is woefully in need of some essential functionality bug fixing
and here
Spaces are very aggressively culled in the Rich Text Editor in certain circumstances · Issue #17007 · laurent22/joplin · GitHub
Check the GitHub issue for the circumstances required for this space eating bug to begin occurring.