No, I wouldn't do that in the same pipeline construct, it would break it since it doesn't do a Passthru of the HostSystem objects.
Make a separate one before the one with Get-Compliance.
...
$esx = Get-VMHost -Name (Get-Content "C:\esxihosts.txt")
$esx |
Scan-Inventory
$esx |
Get-Compliance -Detailed |
...
To avoid doing a Get-Content and the Get-VMHost twice, I placed that on a separate line, and store the results in a variable