In Super Mario Bros, you can access warp zones in three areas of the game. There are two of these that are important for the minus world glitch: the one at the end of World 1-2 (following the exit pipe) and the one at the end of World 4-2 (also following the exit pipe).
The first warp zone takes you normally to World 2, 3, and 4, while the second one only allows the player to World 5, however, the warp zones internally must have three locations.
Internally, the game represents the second warp zone mentioned as World 36, World 5, and World 36 again. This can be verified by looking in a level editor, as shown here:

This was done, because the 36 (0x24)'s tile is a tile that takes the color of the current background (for all intents and purposes, transparent). The first nine represent the numerals 0 through 9, and the next 26 being capital letters (A-Z).
This gives the appearance in World 4-2 of a warp zone with only one location, as shown in the screenshot below:

For unknown reasons, the World 4-2 warp zone is the "default" warp zone, and it's warp zone data is used if there is no other data loaded. Normally the game loads the data from the first warp zone when you walk to the end (scrolling the screen), but performing the wall glitch moves the character without scrolling the screen. There is a scroll stop tile which moving into the warp zone area activates, which refreshes the current warp zone data.
Because when you perform the wall glitch, it moves the character without scrolling the screen, you never scroll far enough to activate the scroll stop which refreshes the warp zone data. Because of this, the default is then used, and because the pipe exists, you are free to swim in the never-ending ocean that is World 36-1.
(It's worth noting that in the Famicom Disk System version of the game, you get an underwater version of 1-3/5-3 instead, followed by World 2-3/7-3, and then an underground version of 4-4.)
But aren't there only 8 worlds?
There are eight intentionally developed worlds, with four levels each. However, the game doesn't stop at World 8. In fact, theoretically there are a total of 256 valid worlds (0-255).
A byte stores both the world counter and level counter. When a level is loaded, it loads an area from an address. For worlds 0 and 9-255, it loads other data as the room offset. A Japanese fan site has documented all of the worlds and levels and even describes the mechanism on how Super Mario Bros. loads the levels (and why the worlds work they do).
Worlds 2-2 and 7-2 are duplicates of each other, and it also happens to be World 36-1 in the NES version. Because no pipe data in ever loaded (it is loaded when 2-2 and 7-2 load I believe) it uses the default start position for the pipe which is the beginning of the level.
Is there more to this?
Yes. In Season 3 Episode 35 of Pop Fiction, the team behind the internet show covered more of these "lost levels", sourcing Legends of Localization. They found that using cartridge hot swapping (and a form of memory corruption), one is able to access all 256 worlds.
Most are unplayable and load garbage data, sometimes from RAM, but some are levels from the actual game, either with the correct tileset or not.
Videos of all 256 worlds can be found here.
Some Further Reading
Minus World - Super Mario Wiki
Deconstructing the Minus World
Marionaire