Short answer: Yes — the sentence is grammatically correct.
Here is a simple, step-by-step explanation for a 7-year-old:
- What the sentence means: It tells us that the skunk moves in a special way to warn others before it sprays its smelly spray.
- Why the comma is there: The part that starts with "Before" comes first (that is the introductory part), so we put a comma after it. That makes the sentence easier to read.
- Who and what: "the skunk" is who the sentence is about. "does a warning dance" is what the skunk does. The words match each other correctly.
- About the words: "it" refers to the skunk, and "smelly spray" describes the spray. The sentence is clear, but we can make it a little simpler.
Two simpler ways to say the same idea:
- "Before it sprays, the skunk does a warning dance."
- "Before a skunk sprays, it does a warning dance."
Both of those are correct and a bit shorter. But your original sentence is fine to use.