How does Drupal generate form ID for a form?
user_profile_form is defined in user.pages.inc file in user module directory. 

The id of the form is the function name which generate the structure of the form in Drupal System. When we call drupal_get_form, it call function name to build the form array.

There is a function drupal_prepare_form in form.inc in includes directory of the Drupal root.


  drupal_prepare_form function prepares a structure of the form array
  and adds required elements, executes any hook_form_alter functions
  and optionally inserts a validation token to prevent tampering.


Code Snippets to generate form id:

if (!isset($form['#id'])) {
    $form['#id'] = drupal_html_id($form_id);
  }