Get additional category field when outputing entries grouped by categories
Just focusing on the assets part I would try to eager-load the image and insert it into your template that way.

{% set entriesByCat = {} %}
{% set entries = craft.entries.section('words').find() %}
{% set cats = craft.categories.group(themes).find({
    with: ['categoryImage']
}) %}

{% for cat in cats %}
  {% set entries = entries.relatedTo(cat) %}
  {% set catImage = cat.categoryImage[0] ?? null %}
  {% if entries|length %}
    {% set entriesByCat = entriesByCat|merge({ (cat.title): { entries: entries, image: catImage}) %}
  {% endif %}
{% endfor %}

{% if cats|length %}
    {% for catTitle, catInfo in entriesByCat %}
        &lt;div class="category-title"&gt;
          &lt;h2&gt;{{ catTitle }}&lt;/h2&gt;
          &lt;img src={{catInfo.image.url}}&gt;
        &lt;/div&gt;
        {% for entry in catInfo.entries %}
          {# Entry content goes here... #}
          ...
        {% endfor %}
    {% endfor %}
{% endif %}


You may want to change the naming convention a little bit, but I just wanted to try and stick to yours as is.