The browser uses them to work out the aspect ratio and reserve space before the image loads, so the page doesn't jump
Browsers turn the two attributes into an aspect-ratio for the image. So even with height: auto, the browser can reserve the right height before any bytes arrive. Without them, the image has zero height until it loads, then pushes the content below it down. That jump counts towards CLS (Cumulative Layout Shift: how much visible content moves unexpectedly).
"Download a smaller file" is the tempting wrong answer. The attributes don't change which file is fetched. srcset and sizes do that.