When I had this type of error, it was because I was trying to render something without a display connected. (I was using a docker so it may not have been the exact same issue)
You may want to run the script with the headless argument, since you are connected using ssh there is no screen to render to.
On a side note, ssh -XC may work without the headless argument, but that’s not really viable.