Depending on which language you're studying, grammar may be the bane of your existence. Sometimes it feels like someone invented grammar just in order to torture learners like you. This is not in fact true.
Human languages are by natural irregular, with many phrases that are simply "not said this way" and grammar is people's attempt to explain and bring structure into this vast sea of irregularities. This means that you CAN skip learning grammar completely and just keep getting corrected that "we don't say it that way", or you CAN internalise a 500 page tome on your target language's grammar and be aware of obscure rules that you'll only need once a year, but most people prefer something in between: learn those 20 pages that will eliminate over 80% of mistakes and leave the rest to be corrected naturally.
Examples from ESL: most English learners have learned that the 3rd person singular present tense shall end in -s: "he wants" and not "he want". This rule is easy to memorize and comes up all the time, so it is a great investment. By contrast, most English learners have not learned the grammar rule that the expected order of adjectives is opinion - size - quality - shape - age - colour - origin - material - type - purpose: "my amazing new red silk dress" rather than "my new silk amazing red dress". This grammar rule is hard to memorize and it's not very common to use several adjectives in a row, so many textbooks don't find it worthwhile to cover this rule and learners tend to learn it by unconsciously imitating examples they've seen, or getting corrected on the odd occasions they get it wrong.
Personal note: I have found grammar books and Wikipedia articles on a language's grammar to be consistently unhelpful. They overwhelm me with the amount of grammar that I could (should?) be learning. They also pretend that a language has dozens of possible declensions, when a reasonable person could decrease that to 3-4 patterns with some exceptions, usually to obey spelling rules. For me, the perfect amount of grammar - at least until B2 level - is what is taught in self-study textbooks like Teach Yourself, Colloquial or Assimil. If you collate all the grammar sections from one such book together, it comes out to about 20 pages or less, and it's definitely enough to have wide-ranging conversations without irritating your conversation partner.
Assuming that you have identified the parts of your target language's grammar that are most useful to know, how should you actually study them?
Learning one rule
Assuming that you are trying to memorize a single rule rather than a table, the best approach is to look around you to find phrases that you already know that use this rule. For example, my boyfriend was trying to learn the endings of the German Genitive. As a board game geek, he knew that the board game industry's most prestigious award is called Spiel des Jahres (game of the year) - and "des Jahres" is an example of the Genitive (for masculine or neuter singular). After realising that, he always remembered how the Genitive is formed.
There are plenty of examples you can use, for example phrases from your favourite TV series and movies ("I'll be back") or set expressions like target-language greetings and well-wishes that you learned before being aware of grammar. Just look around and you'll find some.
Learning many rules at once
If the above approach doesn't work out because you want to learn a table's worth of rules at once (e.g. a conjugation or declension), the tried-and-true method, handed down by centuries of Latin students, is to recite the table, top to bottom, with an example word that should ideally have two syllables. Rosa, rosae, rosae, rosam, rosa.
Always recite them in the same order and with the same example word. When you later need to apply the same rule to another word, you will mentally recite the example word, stop at the form you need, and then apply the same change to the word you need. This is slow and tedious at first and it will get faster, until you don't need this crutch anymore and just apply the right ending without having to recite. Grammar rules are always just a crutch on the way to intuitive use - the crutch is nevertheless very useful, it enables you to start walking sooner than if you didn't have a crutch, and to help build up those muscles that you'll need when you don't have the crutch anymore.
As you recite the table, you will probably develop a rhythm or even turn it into a little song of sorts. This is great! Don't fight it! Rhythm and melody will help you memorize. Careful though: some Latin teachers report that their students have been mistaken as casting a curse when they were reciting their conjugations.
After learning the rule(s) this way, you still have to practice it in order to ensure that the rule is stored in your long-term memory. I recommend to do some intensive practice at first: during the first week after memorizing the rule, do many grammar exercises that require you to apply the rule. You are not limited to your textbook in this - just google e.g. "Spanish present tense conjugation exercises" or "ejercicios para practicar el presente" and you will find more exercises than you can possibly complete. The same is true even for smaller languages like Croatian. How do you know when to stop using these exercises? When you get 100% correct without much effort. (Try again in a couple days though, to see if this knowledge has stuck with you.)
Afterwards, make it a point to notice this particular grammar point when reading, writing or speaking the language. It's overwhelming to try to pay attention to everything, so give yourself permission this week to ignore everything except this point that you just studied. This will greatly increase your familiarity.
Divide-and-conquer is also the best strategy for languages that have a lot of cases, like Slavic languages. Don't try to get all cases correct immediately, instead tackle them bit by bit. For example, for Serbo-Croatian one rule is "the Genitive singular ends in -a, except words that already end in -a get -e instead". Assuming you know what the Genitive is, that rule doesn't sound like too much to handle, does it? Pay attention to that for a week or two and then tackle the next.
Good luck with your language learning!