Question: My brother and I recently decided to beat *Zelda II* on NES. When we finally reached the end screen, after nearly three months of zero-cheating torture, we had all the spells, all items, all magic containers, all heart containers, level 8 on everything, had fully beaten all temples (meaning they turn into mountains so you cannot re-enter them)... but still somehow four keys left.

Even after we had found the "Magic Key", which according to the cryptic manual "can open several of the locked doors" (in contrast to the original game where it just meant "unlimited keys"), the game kept giving us several normal keys in the last two temples, which never went anywhere. There were four nonexistent doors left for the keys to open. Just not present anywhere. And we made careful maps to really scan through each temple.

Isn't the Magic Key *required* to even get anywhere in the second-to-last temple? We had zero keys for the longest time until we found that key and could proceed into that temple's first (and only) locked door... only to get more keys inside. But no doors anywhere to actually use the keys. Not even ones that open with the Magic Key. No doors period.

Also worth to mention is that, unlike the first game, *Zelda II* has no way to *purchase* keys. They are always found or rewarded for beating a mini-boss, and appear to be presented as very important objects.

Also, a person in the game literally tells you to "use the keys in the same palace as where you find them". I wonder what that means since you appear to have no choice?

Am I fundamentally confused about what it means when a temple turns into a mountain tile (and prevent you from re-entering)? Does it perhaps only signify that you beat the boss and got out of the temple, but there are no guarantees that you found all items/secrets inside?

How could we have four keys left?

Answer: 
There are two reasons for this: a game design one, and a technical one.

The game design reason is simple. There are doors in each dungeon that you don't have to open. Some doors only lead to minor rewards like a point bag or magic refill, neither of which is required to beat the dungeon. Once you do beat the dungeon, which consists of nothing more or less than obtaining the dungeon's main item and placing the crystal into the statue, the dungeon is replaced on the world map with a mountain tile and is no longer accessible, leaving any still-locked doors behind while Link takes the keys with him.

Additionally, one of the effects of the Fairy spell is that, in fairy form, Link can fly "through the keyhole" of locked doors, bypassing them entirely. If you have any keys when you try to do this, the door will still be opened (this might be considered a glitch, depending on who you ask), but if you have no keys and approach a door in fairy form, you can just fly right through.

---

The technical reason is that when Link encounters a boss or miniboss, the screen is locked so that you can't leave the boss arena. Every boss drops a key to unlock the door right behind their arena--likely both to give an in-universe reason for you to be fighting them instead of running past, and to give you a "you beat the boss and got a thing" sense of achievement similar to the orbs after every Castlevania boss.

Perhaps to ensure you can't miss it (as it would probably--but I can't say for sure--despawn if you left the room), the screen remains locked until you pick up the key. As a side effect of this decision, the only way in the code for the screen to unlock is for Link to pick up a key. Rather than complicate matters by making special cases for the handful of bosses you fight after getting the magic key, they just have those bosses still drop keys so that you can unlock the screen and move on.
As far as I recall, you could fly through keyholes with the Fairy spell ( I just looked it up and apparently this wasn't possible on European versions of the game, wild! ), so even before getting the Magic Key you have the potential to skip using some keys, magic power allowing.

If you're feeling really wild, with this feature you can end the game with a letter number of keys left over, but that takes some doing.

Edit to include clarification from @wizzwizz4 in regards to holding more than 9 keys: " It indexes into the tileset. If it's not got any base support, 10 will just use the next tile after 9."

Edit edit: Source: I played the living crap out of this game with my little brother. <3