I want to add number after post tittle for each category

Here’s an untested edit of your code to use the post’s first category in the count:

add_action('the_title', 'dk_auto_numbering');
function dk_auto_numbering($title)
{
    $post_ID = get_the_ID();
    $the_post = get_post($post_ID);
    $date = $the_post->post_date;
    $maintitle = $the_post->post_title;
    if ($maintitle == $title && $the_post->post_status == 'publish' &&
        $the_post->post_type == 'post' && in_the_loop()) {
        $categories = get_the_category($post_ID);
        if (is_array($categories) && count($categories) >= 1) {
            $first_category_id = $categories[0]->term_id;

            global $wpdb;
            $count = $wpdb->get_var(
                $wpdb->prepare("SELECT count(*) FROM $wpdb->posts AS p " .
                    "INNER JOIN $wpdb->term_relationships AS tr ON tr.object_id = p.id AND tr.term_taxonomy_id = %d " .
                    "WHERE post_status="publish" AND post_type="post" AND post_date <= %s", $first_category_id, $date)
            );

            if (isset($count)) {
                return $title . ' – Chapter ' . $count;
            }
        }
    }
    return $title;
}

I’ve moved the has-something-else-already-modified-the-title check out to the top level, to run it before the database query, plus a few other minor rearrangements. It’s slightly asymmetric in that it uses the current post’s first category but counts any earlier post that has that category at all, but hopefully that’s enough for what you want: if you need any more complicated category handling you can edit the SQL.

As I said in my original comment though I think these counts ought to be pre-computed and cached against the post in post meta, rather than run as a separate query for every post title shown on the page.