Is this on an iPad? There is a feature on iPads where if you tap with two fingers, it selects an entire word. If you double tap with two fingers, it selects an entire sentence. If you accidentally do this, and keep typing, it overwrites what you selected. I’ve done this many times, and I don’t know any good way around it (other than hitting undo, or using an external keyboard).