$out not working in mongodb Sharding
The error message indicates that, in your cluster, there was shard what didn't have primary available and query went to secondary and with the current configuration, a query to secondary was not allowed.

So, what was a reason that there was no primary? An answer to that is the key to solve the problem.

Can you check (by login to every RS) that every sharded replica set have primary available? Second possibility is that config servers don't have up-to-date information of your shards configuration... But that should not be possible if your cluster works other ways fine.