Order a list of categories by number of entries, key not being set
If you encounter problems with assigning variables as the keys, what about putting all your values into objects?

{% set catObjects = [] %}

{% for cat in allCats %}

    {% set catObject = [
        { catId: cat.id, catCount: craft.entries.relatedTo(cat).total()  }
    ] %}

    {% set catObjects = catObjects|merge(catObject) %}

{% endfor %}