The shardCollection command consults a property on the database called sharded. If sharding has not previously been enabled on a database though enableSharding, the shardCollection call will fail.
If a mongos instance has cached a database entry, there is no mechanism to cause it to refresh it.
Because of this, if multiple mongos instances have been operating on a given "unsharded" database, enabling sharding on that database will only be reflected on the mongos instance where enableSharding was called and all calls to shardCollection on these instances will continue failing, even though the database has been marked as sharded.
Since shardCollection is not a frequent operation, it should be made to read the "sharded" property directly from the config server instead of the cache.