If the system PATH variable is longer than 1022 characters, OPTLINK will fail to find phobos.lib and link D programs. My guess is that the PATH variable contents is clobbering the LIB variable's, which happens to be adjacent in memory. It's possible that the order of variables within the environment block also matters.
Could also be that there's a + or something in PATH (e.g. when GTK+ Runtime is installed). See Issue 4831.
I don't think so. The problem manifests if the PATH is over 1022 characters, but not when it's exactly 1022 characters long. The number is very close 1024, which I doubt is a coincidence.
Looks very much like a duplicate of 1327 which you seem to have found later on. Marking as such, if not, please re-open an issue on OPTLINK's Github (https://github.com/DigitalMars/optlink/issues), I am cleaning up OPTLINK-only issues. *** This issue has been marked as a duplicate of issue 1327 ***