After a lot of research and trying different things, I came across this page https://core.trac.wordpress.org/ticket/50976 which wasn’t exactly the same as my problem, but the cause of this was also what broke my site.
To get around this, without having to change my URL structure and therefore get google to reindex all my pages, I had to get a list of all the pages using certain templates (that made use of the example.local/courses/1234/?title=something) and then create an add_rewrite_rule for each of the pages.
/**
* Register new rewrite rules
*/
function rewrite_pagination_rules_for_content_items() {
/* get list of pages the rewrite is required for based on a particular template used */
$pages = get_list_of_paginated_pages();
foreach($pages as $page) {
/* strip off domain name and first slash */
$domain_start = strpos($page['url'],'://');
$domain_finish = strpos($page['url'],"https://wordpress.stackexchange.com/",$domain_start+3);
$url = substr($page['url'],$domain_finish+1);
$post_id = $page['id'];
//echo '<br/>url=".$url." post id = '.$post_id;
add_rewrite_rule("^(.*){$url}([0-9]*)/?$",
'index.php?page_id='.$post_id,
'top');
add_rewrite_tag('%id%','([0-9]*)');
}
}
add_action('init', 'rewrite_pagination_rules_for_content_items');