I ran your code in a Windows 2016 domain – PowerShell 5.1 – and it worked.
Test-Connection uses the Win32_PingStatus WMI class and requires a DCOM connection to the remote machine. I'd suggest testing Test-Connection against one of the failing remote machines directly rather than in the workflow. I'd also suggest that you test get-WMIObject against the failing machine to help determine if there is a DCOM issue
The code works. The problem is that when I load the module that has the above code in it I get the 'A workflow cannot use recursion' error. Don't know its giving me that error when the code actually works.