Q:

Were the dungeons in Legend of Zelda designed to fit together?

As can be seen in the image below, the dungeons of Legend of Zelda fit quite well together.

Were they designed to be, or is this just a coincidence?
Does this make them easier to store, with the empty spaces used for caves for instance?

A:

As seen in that incorrect† image, the levels seem to merge well.  This wasn't a case of "Let's take these shapes, and see if they... whoa!  They fit together!"
It was more like, "Here's a big rectangle.  Let's cut away some shapes."
It's kind of like starting with a big batch of cookie dough, or silly putty, and cutting shapes out of that.  Then, at the end, saying, "Look at how all those shapes fit neatly together!"  Well, yes, of course they do.  Because having all the pieces fit together was not an "end product" that they had to work to try to create; it was actually the starting point.
The Cutting Room Floor: Prerelease: The Legend of Zelda has some information, including those drawn maps, and interview info with Miyamoto about this.

Tezuka: Basically, we were going to make lots of dungeons using one square per room, and lay them out like a jigsaw puzzle.
Iwata: In order to fit in as many dungeons as possible given the limited memory, you were making them like you were doing a puzzle.

Another spot on the web that discusses this is Siliconera.com article: "Thanks To A Mistake The Legend Of Zelda Got A Second Quest", which also shows the layout of the levels in the original hand-drawn maps seen at this article on the web.
The "Mistake" in question (as noted by The Cutting Room Floor: Prerelease: The Legend of Zelda and Siliconera.com article: "Thanks To A Mistake The Legend Of Zelda Got A Second Quest") is that during the game's development, half of the memory used for map layout got lost for a while.  So they crammed in the levels in the remaining space.  Then the memory got found again, but they determined that the game length felt pretty good after they crammed things into half the space, so instead of making the levels twice as wide to explore through, they just made other levels and made it so that you access them through the "second quest".
Having this "mistake" revealed helps to explain why there is a pre-release screenshot, that you can view on The Cutting Room Floor: Prerelease: The Legend of Zelda, that shows Level 2, Moon, that looks twice as wide.  At one point, the levels we have were apparently going to have about the same shape, but twice as many underworld rooms per quest (and half as many quests).
† So, yes, as noted above, the image used in the Question shows a layout that does not match how the game stores the levels in memory.  Level 9 is actually located west of levels seven and eight, not east of levels seven and eight.  We can see that in the hand-drawn maps shown in the articles mentioned above.
Also, the map layout is known.  Some software named Dungeon Master, a map editor makes clear that if you walk off of any of those five "world" maps, then you leave the area and go back to the overworld screen with the corresponding entrance. (If you leave the overworld, it brings you to the start screen where you get the Wooden Sword). So walking off the outer edges makes it pretty clear what the actual level layout is. Also, walking between levels 9 and 7 is possible with modified walls, so that makes it rather clear that the East side of Level 9 touches Level 7, not the edge of that area of underworld map data.

A:

Typically in cases like this, they are designed to fit together.
Actually, it's not so much that they are separate maps that happen to fit together, but rather it's just one big map and each 'dungeon' is simply a piece of it.  This can simplify the game design because what appears to the player as moving to a new map can be coded internally as simply moving the player to a new place on the same map.

A:

I don't know whether this was deliberate for Legend of Zelda, or whether it used any of these techniques, but here are some benefits of doing so:

It's easier to keep track of the levels if you're storing them like that in the ROM.
You can draw the whole game on one big piece of paper.
Going off the edges of the dungeons can be implemented more easily if they're stored like that in the ROM (dungeons don't need to store which dungeons they connect to).

