Check if Category is in Query
I would construct an array of the category slugs outside of your childCategories loop (using twig's merge filter:

{% set queryCatSlugs = [] %}
{% for category in query %}
  {% set queryCatSlugs = queryCatSlugs|merge([category.slug]) %}
{% endfor %}


Then your childCategories loop can use twig's containment operator (in) for the test:

{% for childCategory in childCategories %}
  {% if childCategory.slug in queryCatSlugs %}
    ... matches ...
  {% endif %}
{% endfor %}