to me, it kind of sounds like you have inadvertently activated a "hot corner" for the top right corner of your desktop.
for Ventura or Sonoma, go into System Settings > Desktop & Dock. then in the right panel, scroll down until you see the "hot corners" button.

then click the "Hot corners" button and ensure if it is set as "Lock Screen". if it is, you can change it to show "-" and your screen will stop locking whenever you mouse over your top right corner.

but in monterey and before, go into System Preferences > Desktop & Screen Saver.

then in the "screen saver" tab, click on "hot corners".

and again, check your "hot corners" settings.
