Your added CSS can go in the Additional CSS section of the customizer or style book. Which one depends on the type of theme your have, classic or block respectively.
I don’t know why the category terms reappear after the post listing. It’s likely a quirk of your theme. The code works as expected on the default classic theme Twenty Twenty-one. The code probably needs to check some condition prior to echoing out the terms. Perhaps your theme’s dedicated support forum could advise.
Or maybe it could be hidden with CSS by using the :last-child
pseudo-selector. You will want to place the terms in a div container anyway so they can be easily targeted with CSS selectors. Like this:
echo '<div class="cat-terms">',
implode(' ', wp_get_post_categories( $post->ID, ['fields'=>'names',])),
'</div>';