Insert a variable in pre_get_posts

You can not use a variable inside a function which has been defined outside the function!
Get the value from $_GET inside the function.

function my_home_category($query) {
    if (isset($_GET ['p'])) {
        $catvar = get_cat_ID($_GET ['p']);
        $query->set('cat', $catvar);
    }
}
add_action( 'pre_get_posts', 'my_home_category' );