When closing the door, the glass should only rise after the door is latched closed, not before.
When it does rise, and it goes the wrong side of the recess, this is a purely 'mechanical' issue.
The runners being out of alignment - either badly adjusted, worn or there is damage to the door - eg...