I was able to translate as west melon and south melon. The melon part makes sense, but why were directions used? I saw the sui (water) kanji for watermelon, but it is no longer used.
The kanji spellings are directly borrowed from China, so it's Chinese that call them so. Cucurbits are originally tropical plants, thus they were all imported to East Asia at some points of history. 西瓜 suggests that it came from Western Regions, and 南瓜 from Southeast Asia. As they are tropical plants, 北瓜 shouldn't exist logically, but according to a Chinese wiki it is a Chinese dialectal name of zucchini and the like. 東瓜 seems totally nonexistent except being a rare variation of 冬瓜 (wax gourd).
The Japanese name スイカ is a 唐宋音, or transcription of later Chinese sound (西 is usually read セイ or サイ, which are older ones). It is a quite natural consequence that it was associated with 水 due to more regular reading and the juicy fruit (as much as how English calls it watermelon), but the spelling is rare now. As for カボチャ, it reflects the fact that it was imported to Japan via Cambodia (カンボジア), though its origin is Americas.
Incidentally, cucumber is called キュウリ and 胡瓜 in kanji. 胡 is a Chinese word to call "barbarians" who live to the west of China, and its Japanese name is from き "yellow" + うり "melon, gourd". It may baffle modern people who only eat green unripe fruit of it, but it turns yellow when mature. Interestingly it is now mostly called 黄瓜 in Chinese, but this spelling is rare in Japan.