Strictly speaking, it is grammatically incorrect to omit "it".
However, everyone commits this error so it will never get you in trouble. Nobody will notice the error.
Let me explain why omitting "it" violates grammatical rules. In brief, "like" is a verb that needs to have an object. "I like" is a bad English sentence.
In #2, "when you dance" is an adverbial phrase that modifies the verb "like" and "it" is the direct object. This becomes more clear when you rewrite the sentence this equivalent way:
"When you dance, I like it."
Now you can see why "it" is necessary. Without "it", "like" lacks the object that it needs:
"When you dance, I like." (BAD)
It is tempting to try to defend the sentence "I like when you dance" by claiming that "when you dance" is a noun clause and the direct object. However, noun clauses cannot be anchored by "when". "When" is an adverb and "when you dance" is an adverbial clause that cannot be the direct object of the verb.