How can I update the permalink everywhere for a custom post type?

This line:

$post_link = str_replace( "https://wordpress.stackexchange.com/" . $post->post_type . "https://wordpress.stackexchange.com/", "https://wordpress.stackexchange.com/", $post_link );

isn’t doing what you expect because your post slug isn’t $post->post_type, it’s sp, as set here:

$rewrite = array(
    'slug'        => 'sp',
    'with_front'  => false,
    'pages'       => true,
    'feeds'       => true,
);