Grammar is the system of a language. People sometimes describe grammar as the "rules" of a language; but in fact no language has rules*. If we use the word "rules", we suggest that somebody created the rules first and then spoke the language, like a new game. But language did not start like that. Language started by people making sounds which evolved into words, phrases and sentences. No commonly-spoken language is fixed. All languages change over time. What we call "grammar" is simply a reflection of a language at a particular time.
Do we need to study grammar to learn a language? The short answer is "no". Very many people in the world speak their own, native language without having studied its grammar. Children start to speak before they even know the word "grammar". But if you are serious about learning a foreign language, the long answer is "yes".
*Except invented languages like Esperanto. And if Esperanto were widely spoken, its rules would soon be very different.