Him can refer to any noun previously used if that noun takes masculine pronouns. In some (most?) European languages, inanimate objects can take masculine or feminine pronouns. In English, with a few exceptions, only people and animals take masculine or feminine pronouns.
You are proposing a rule that limits what a pronoun can refer to based on the antecedent's position in the previous clause or sentence. There is no such rule. For example, when I wrote you I wasn't even referring to a noun I had previously used.
In the example, the nouns are Kumbhakarn, Sugreev, head, and rock.
If you meant that the rock lost consciousness, you might say
Kumbhakarn then smashed Sugreev's head with a rock, causing it to lose consciousness.
but that makes no sense because the rock wasn't conscious to begin with.
From context, it's extremely unlikely that the action would render Kumbhakarn unconscious, so it's unambiguous that him refers to Sugreev. However it is acceptable to repeat Sugreev's name instead of using him. (I disagree with the statement in the previous answer that repeating the name is not good style.)