Using form_set_value with commerce in custom form
The code executed from form_set_value() is the following one.

function form_set_value($element, $value, &amp;$form_state) {
  drupal_array_set_nested_value($form_state['values'], $element['#parents'], $value, TRUE);
}


$checkout_pane['pane_id'] . '][donation_amount' is a string, even if $checkout_pane['pane_id'] is an array; this is because the string concatenation operator cast an array into a string.
If $element is a string, then $element['#parents'] is a string made of one character, similarly to what happens with $string[0], when $string is set to 'long string with many characters that are added just to make the string longer'.

That explains the error about the second argument.

With form_set_error(), $checkout_pane['pane_id'] . '][donation_amount' works because the function is expecting a string as first argument, and the format of that string is exactly the format of the string you are passing. 

The first argument of form_set_value() is a form API array for the form element for which you want to set the value. That is not the content of $form_state['values']. As that is the code for a form validation handler, it should be similar to the following one.

function mymodule_form_validate(&amp;$form, &amp;$form_state) {
  // …
  $form[$checkout_pane['pane_id']]['donation_amount']['#parents'] = array($checkout_pane['pane_id'], 'donation_amount');
  form_set_value($form[$checkout_pane['pane_id']]['donation_amount'], '999', $form_state);
}


You still need to verify the content of $checkout_pane['pane_id'] is effectively the parent of the element you want to change. For that, you can install the Devel module, and print the structure of $form using dpm($form);.

As for the answer given in the other question, I can say it is based on the description present in form_set_value() for the $element parameter.


  The form element that should have its value updated; in most cases you can just pass in the element from the $form array, although the only component that is actually used is '#parents'. If constructing yourself, set $element['#parents'] to be an array giving the path through the form array's keys to the element whose value you want to update. For instance, if you want to update the value of $form['elem1']['elem2'], which should be stored in $form_state['values']['elem1']['elem2'], you would set $element['#parents'] = array('elem1','elem2');.