I feel the need to answer this once and for all.
In order to explain this, I have to explain complicated stuff(didn’t even realize Windows was this complicated before joining UiPath).
Many UiPath Activities including Take Screenshot requires a Default Desktop where Interactive Window Station is attached. And wow that was mouthful.
Here are some documents you can read.
“default desktop with interactive window station attached”, Let me just call this GUI, because that is what it essentially is. UiPath can run on a session without any GUI being depicted, or GUI being depicted. Typically you should log out of the user instead of disconnect, because UiPath will use the disconnected session when you disconnect(Thats how it works as of 2021/2/17). This session would not have GUI. Taking screenshot requires a GUI, which has the coordinate details of the place to take screenshot, and because the GUI doesn’t exist, you get a null reference error(which in java is called null pointer exception).
Anyways, as dwyrock explained, signing off is needed.