1- why there are html code if the browser will redirect it automatically
It's traditional from the times where 302 was new and not every client understood what it means. It is not really needed today and uselessly wastes bandwidth.
If you have a proper 302 response, that is a Location header is present, the body will be ignored and nothing will be executed.
There are firewalls which can be bypassed this way because they don't expect the browser to execute the body of 302 responses and thus skip inspection even if no Location header in the response indicates the target of the redirection.