Order Categories by Character Count

This is probably more a question about PHP rather than WordPress, and as such may be closed as off-topic for this site.

That said, you can usort() to sort an array using a custom comparison function:

usort(
  $listings->loop['cats'],
  function( $a, $b ){
    return strlen( $a->name ) - strlen( $b->name );
  }
);

After the call above, the $listings->loop['cats'] array will be ordered from smallest category name to largest.

Sorting from shortest to longest will pack all of the smallest items together nicely – but it also concentrates the largest items, which may ultimately take up an entire line a piece if not paired with a short item. A more space-efficient approach is likely one which would mix long and short items, but it might not feasible if you don’t have a rough measure of the width constraint beforehand.