The eval command on mongod calls into the js scripting engine.
Since eval() is called on a database, not a namespace, it does not check the shardVersion sent in the request (or the shardVersion for the connection) directly.
It does this check by calling ShardingState::haveLocalShardingInfo():
This function assumes the collection is sharded if:
1) the OperationShardingState has a shardVersion (aka, a shardVersion was attached to the command in the request)
2) the connection used for sending the eval() command previously set a shardVersion for the namespace.
The mongos EvalCmd, which forwards the command to the primary shard for the database eval() was run on, does not attach a shardVersion to the cmdObj.
On the other hand, the passthrough() function called by mongos's EvalCmd uses ShardConnection on an empty namespace.
Therefore, only if the connection mongos gets from the pool had previously set a shardVersion for a namespace accessed by the script (e.g., due to a different, prior command), will the shard host have a ShardedConnectionInfo with a non-UNSHARDED version for the namespace, and only in this case will the haveLocalShardingInfo() check on mongod work if the collection is sharded.