How the redirect_to parameter is added to wp_login.php when trying to access wp-admin?

Redirect parameter is created at auth_redirect function:

https://core.trac.wordpress.org/browser/trunk/src/wp-includes/pluggable.php#L1064

and it is added at wp_login_url function:

https://core.trac.wordpress.org/browser/trunk/src/wp-includes/general-template.php#L328