How were naval mines stored on ships in WW2? Were they towed behind the ship (which seems highly unlikely and HIGHLY dangerous), or were they kept in some sort of rack aboard the ship?
Dedicated minelayers would store their mines on deck. They would have a rapid deployment system, usually consisting of trolleys on tracks.
They would plan their delivery based on water depth, type of mine, and the nature of the field they were setting.
HMS Manxman (M70), a WW2 minelayer of the Royal Navy is a good example. She was designed to be exceptionally fast, even for a warship. They took the powerplant from a heavy cruiser and stuffed it into a destroyer-sized hull. With 72,000shp driving a displacement under 3,000 tonnes she could hit a top speed very close to 40 knots - around 75kph.
The idea was to hurtle into the area to be mined at night, deploy her 156 mines fast, and get out before shore defences could respond.
To do this, the crew would prepare the mines in advance , with their anchors, tethers and warhead. They would be mounted on trolleys on tracks on the mine deck. As she steamed through the zone, the mines would be launched over her stern. Just before the mining run, the mines would be individually armed. Until this point, the risk of accidental detonation is tiny (unless the ship is hit by enemy fire.) Even when armed, the mine presents very little threat to the vessel laying it.
There's a site here that has some pictures of HMS Manxman loaded with mines. You can clearly see them arrayed on tracks on her main deck.
There's a good article here that talks about mine warfare in WW2.
I can't find any academic sources that include details of exactly how mines were stored and handled. There's a lot written about the tactical and strategic impact of mine warfare, and a lot of experiential stuff from victims of mines. There's also quite a lot of information about post-war mine clearance challenges. The precise details of storage and handling would exist somewhere in the operational documents of the navies involved. It's the sort of thing that doesn't get declassified, as the basic principles apply today, so it may present some challenges to a historian.