Regarding your two examples:
I got my hair stuck in the nail.
My hair got stuck in the nail.
The former specifies that you are responsible, by usage of the pronoun "I" as the subject (actor) of the sentence.
The latter leaves open as to who is responsible; it could be you, or another person, or the outcome of circumstances (maybe the wind blew your hair).
Regarding this usage of "got" (past tense of "get"):
3.1 [as auxiliary verb] Used with past participle to form the passive mood.
‘the cat got drowned’
v. intr. 3. b. Used with the past participle of transitive verbs as a passive voice auxiliary: got stung by a bee.