There are many possible reasons how the code wound up being like that. If you could remove the inline styles for margins, height and width and instead add the class "img-responsive" to the image it would render in a more "standard" and expected way on the page. Alternatively you could add
width: 100%; height: auto;
to the inline style, but that would only be a "emergency" solution and not be considered good practice.
However it would probably be best to cleanup the markup so that the caption lives in a div or span with a class name of caption. Why are you not making use of the default caption option in Drupal? If you look at or install a "clean" version of Drupal 8 and create an article and add an image you can see how the caption works. It generates this markup:
<figure role="group" class="caption caption-img"><img alt="Dog" data-entity-type="file" data-entity-uuid="c8b30e3b-8346-4d2b-8df3-86dcff35d274" src="/sites/default/files/inline-images/images.jpeg"><figcaption>This is my nice caption</figcaption></figure>