Category custom template is not showing correct posts

category_name expects a category slug, albeit the name of the parameter.

get_the_category should be used either with an ID or inside the loop – it returns the categories for the given/current post. But even if that worked, you’ll get an array of WP_Term objects – cat_name is not a property. User ->name to get the name, or ->slug to get the slug.

If you know the category ID or slug, you can simply use get_term_by, e.g.

if($term = get_term_by("id", $id, "category")) {
    // set your arguments for WP_Query
    $args["cat"] = $term->term_id;
}