Your analysis is correct: The issue is that all visual automation commands (XClick, XClickText, visualAssert, aiComputerUse,…) need an unlocked desktop. Otherwise Ui.Vision can not take screenshots and thus the commands report an error.
=> See this info:
- unattended execution
- How to run desktop automation on a locked machine
- Disconnecting From Remote Desktop (RDP) While Running Macros with Real User Simulation <= I think this is your issue.