Edit the_category (); for a hierarchical display

You could assign the post only to the child category, and call the function like so:

the_category( ' ', 'multiple' );

This will output (notice the whitepsace between the anchor tags):

<a href="https://example.com/category/parent/">parent</a> <a href="https://example.com/category/parent/child/" rel="category tag">child</a>