media sideload image not working with JPG file

You should check for the special characters in url, sometimes url structures may contain special characters like space, &, ‘ .

use str_repalce to replace known special characters or urlencode.

media_sideload_image works properly with JPG as well so either url contains special characters.

If you can access image through url there is not a permission issue as well which blocks image download sometimes.