Top-loading machineguns like the Madsen and the plethora of designs we see in WW2 (ZB.26, Bren, Type 99, FM 24/29, etc) were intended for fire from static positions using the bipod. Being light machineguns, they were crew-served weapons, and doctrine of the time across most armies had the gunner's assistant responsible for magazine changes. Underside-mounted magazines often left the ground in the way and interfered with loading. Top mounted magazines also had the benefit of allowing the gunner to keep a lower profile, as there was no longer a magazine that needed ground clearance. No magazine on the bottom allowed for the bipod to be shorter while still allowing for a decent vertical field of fire.
Side-mounted magazines offered a lot of the benefits of top-mounted, but were more common on submachineguns and other non-crew-served weapons. Here the benefits were very similar - the shooter could have a very high capacity magazine without having it interfere with their ability to go prone. The big problem here often ended up being balance. The weight of the ammunition and magazine hanging off one side of the gun made it awkward to hold, even in submachineguns like the MP-18 and Sten, where the weight of the ammunition and mags was fairly low.
Ultimately, the shift to underside-mounted magazines was something that didn't really seem to have the same kind of clear, consistent reasoning that influenced a lot of other firearms-related decisions. We'd see top-mounted magazines stick around postwar with many powers for some time. The British stand out in particular, as they opted to update the Bren to the L4 model to accept 7.62 NATO ammunition instead of adopting the L2-model FAL, which was intended to serve the same role. Compared to the L2 in Canadian and Australian service, the L4 Bren was significantly better suited to the role of light machinegun. Another notable case was the Stoner 63 - a Vietnam-era design that included an automatic rifle variant with a vertically-mounted magazine.
The shift to underside-mounted magazines for machinegun use tended to follow two trends - a shift towards automatic-rifle variants of the standard service rifle (RPK, FALO/L2) and a shift towards belt-fed machineguns for smaller-unit use (FN MAG, PKM, M60) As far as side-mounted magazines for submachineguns go, I'm not familiar enough with them to really give an answer. One thing to note is that submachineguns in general began to fall out of regular use after WW2, and where they remained they tended to fall into very niche roles where the benefits of a side-mounted magazine may not have mattered anymore.