Rail guns are legit, but you won't see anyone mounting them on bipedal tanks.
I think it's a situation where Kojima just came up with "walking tank" because it was 1987 and he was only 24 and writing a dumb computer game, but then he was kind of stuck with it because, hey, the series is named after it, so he was stuck making excuses or sidestepping it for the rest of the series.
-Metal Gear 2's initial release actually took place in a totally unrealistic world when the US and the USSR have completed total nuclear disarmament, so when Zanzibarland steals nuclear material slated for disposal with its Metal Gear, it's the only nuclear power. (future MGS games obviously retconned this part)
-MGS1 sort of acknowledges that stealth bombers and nuclear submarines make Metal Gear redundant, but uses the rail gun/stealth warhead aspect to handwave it away (though as you noted, a railgun doesn't need a walking tank). I think there might also have been an implication in the Codecs that REX was also something of a pet project for defense firms that was seeing a lot of bribe money being thrown around.
-MGS2 sidesteps it by having RAY having no nuclear weapons at all. Arsenal Gear has nuclear weapons, but it's just a giant submarine with a huge ass server farm inside of it, not a true Metal Gear at all.
-MGS3 has the Shagohod, which is depicted as a product of space race-era Soviet rocket madness (a rocket-powered tank that uses its own ground acceleration as the first stage of an ICBM). There's a radio conversation where right after meeting Granin (the actual creator of the Metal Gear concept), you talk to your tech and hardware specialist, who is baffled by the idea of a bipedal tank and openly points out how impractical and redundant it is.
-MGS4 again sidesteps the issue entirely. The only new mechs are Gekkos, which are essentially glorified bipedal Big Dogs with guns on them.
-Peace Walker had... Peace Walker (aka Basilisk) which had the twist of it being controlled by an AI and only used for nuclear deterrence. It was essentially supposed to be the basis for a network of Dr. Strangelove doomsday devices: they would be camouflaged from radar and satellite, automatically wander or hide in terrain, and either launch medium range missiles or wander into enemy territory and detonate their warheads to self destruct. Which... is still pretty silly. A lot of Peace Walker is silly.
-Revengeance (though not written by Kojima) had RAYs simply as giant combat mechs, and Metal Gear EXCELSUS at the end is pointed out to be more of a giant spider-mech. It's not bipedal, has no nukes, and a Codec conversation reveals that it's only branded "Metal Gear" for... essentially brand recognition, because actual Metal Gears are strategically pointless.
I can't remember what Portable Ops had. There was RAXA, which was a big ugly machine thing that was boring, and then there was the REAL Metal Gear which was.... attached to the front of an ICBM, because fuck it, just ignore the whole goddamned idea behind Metal Gear to begin with I guess