First of all i would like to say that you understanding in the first part of your post is almost accurate.
Nonces and pre-shared key are the inputs to PRF (HMAC in this case) to derive the initital SKEYID which is used to dervie other keys i.e. SKEYID_d, SKEYD_a, SKEYID_e.
DH shared secret is generated on each end of the VPN tunnel using the DH public value exchanged in packet no.3 and 4 and this shred secret along with SKEYID , cookies and number are used to generate the 3 keys SKEYID_d, SKEYD_a, SKEYID_e.
Once the SKEYID_e is generated it is used to encrypt the ID and Hash Payload in packet no.5 and 6. If both the ends are able to decrypt the packets sent to each other, it authenticates the DH exchange and the keys are identical.
As mentioned above both identity and Hash Payload are encrypted using SKEYID_e. Both payloads contain the information calculated as below. Fore more details Section 5 Page No.8,9)
To answer your first query when we configure VPN the hashing function elected in this case for ex- HMAC gets the input message and key material to generate the 3 derivated keys by the different input values on which it runs the hashing function.
For Ex- to generate SKEYID it used pre-shared key and nonces as the input, In packet no.5 and 6 all the inputs as mentioned above to generate the Hash Payload act as the input material to the hashing function.
To answer your second query SKEYID_a is not directly used in packet no.5 and 6 but it is used to generate the SKEYID_e which is used to encrypt packet no. 5 and 6.
SKEYID_e = PRF (SKEYID+SKEYID_a+DH shared secret+ Cookies + Number)
Let me know if i was able to answer your queries. Hope this Helps
Thanks, Pulkit Bhandari Please mark my response as Solution Accepted if it Helps, Kudos are Appreciated too.