I do German at university and this still caught me out for a minute, this rule is not even necessarily taught at A level in the UK!
Elefant is part of a group of nouns in German which are referred to as "weak nouns". In short, this means that an -n or an -en ending is added in every case except the nominative singular, which we call "the n-declension". This is because in German (and English), there used to be a system of noun inflection which have been lost through centuries in both languages. In German, weak nouns are all that is left of this old rule. You can read more about the n-declension here: http://www.vistawide.com/german/grammar/german_nouns03.htm
Here are some examples using "Elefant" in different cases to demonstrate the rule. Notice how the nominative case differs from the other cases.
Nominative: "Der Elefant frisst" (nominative because Elefant is the subject) - the elephant is eating/eats.
Accusative: "Der Löwe sieht den Elefanten" (accusative because Elefant is the direct object) - the lion sees the elephant.
Dative: "Der Löwe ist hinter dem Elefanten" (dative because of the dual case preposition 'hinter') - the lion is behind the elephant.
Genitive: "Der Schutz des Elefanten ist wichtig" (genitive to indicate possession/source) - the elephant's conservation is important.
I hope this helps!
I suppose the title of Wagner's opera, "Der Ring des Nibelungen", shows that "Nibelung" is a weak noun too. It's also masculine, and I'd been told that all nouns ending in -ung are feminine. Oh, well.
That brings up another question: does the genitive of weak nouns end in -en, and not -es?
"hinter" is one of what we call "dual case prepositions" in German, meaning they can cause both the accusative or dative in German. The way to tell which case to use is to determine if there is motion in the sentence. Motion = accusative, no motion = dative.
We have this in English to some extent: consider "I go into the office" vs. "I am in the office". We use "into" to indicate motion. So in German these sentences would be: Ich gehe ins (in das) Büro - accusative, Ich bin im (in dem) Büro - dative.
Another example: The cat jumps onto the chair - die Katze springt auf den Stuhl - accusative. The cat sleeps on the chair - die Katze schläft auf dem Stuhl - dative.
Back to the sentence from the exercise: the lion is already behind the elephant, so there is no motion - der Löwe ist hinter dem Elefanten - dative. However if we changed the sentence to include motion - the lion goes behind the elephant - der Löwe geht hinter den Elefant - accusative.
Hope this made sense! You can read more here: https://www.bbc.com/bitesize/guides/zq6rk7h/revision/9