WP media attachment location vs permalink

I think a possible solution could be following codesnippet from Mark Kaplun.

To solve issues with this you could remove the http part and WordPress will/should use https instead.

Because the rest of your website is working correctly I assume that further settings are correct and will do their job as wished.

add_filter('the_content','wpse_217012',1000,1);
// remove 'http:' part from any mention of the site url
function wpse_217012($content) {
    return str_replace(siteurl(),str_replace('http:','',siteurl()),$content);
}

Please add the snippet to functions.php (make a copy first) or to a plugin.

Note: Of course is this a solution to achieve a positive result and actually
not pointing on the cause of your problem as it.
I personally would not use a redirect done by code in .htaccess because, as mentioned by yourself already, the rest is working.
Maybe there is a plugin or own code somewhere in functions.php which is causing the problem? Please take also a look at these possibilities.

If I am totally wrong, please let me know and I will remove the answer to prevent other users here on wpse will use the (incorrect)code for an equal problem.