The reason cucumbers, squash, muskmelons and watermelons should not be grown near each other is that they are all cucurbits and may cross-pollinate to produce weird franken-gourds. This myth does have some truth in it, but it is not good gardening advice.
It is true that all of these plants are cucurbits, but they are not all the same species, which reduces the chance that they will cross-pollinate. Summer squash, pumpkins, gourds, zucchinis and some types of winter squash belong to the same species, Cucurbita pepo, and these will cross-pollinate with each other. Muskmelons (Cucumis melo) and cucumbers (Cucumis sativus) are different species and don’t cross with each other or the genus Cucurbita.
Cross Pollination in Cucurbits
When crosses do occur, the resulting seed will contain DNA that is a mixture of the parents, but the fruit will look normal no matter who the father is. You will only see the results of the cross if you collect and plant the seeds.
Sometimes this seed falls to the ground by accident and grows, resulting in weird gourds that the gardener can’t explain. In some cases they incorrectly blame the seed they bought or they contribute the problem to cross pollination taking place in the current season, but the truth is that it is a result of older seed finding its way into the garden.
Cross-pollination is not an issue if you start with store-bought seed or purchase seedlings every year from reliable sources. It is a concern for people who are collecting heirloom seeds, in which case, plants need to be kept separate so cross-pollination does not occur. In this case the recommended separation between different plants is 1/2 mile, according to Suzanne Ashworth in her excellent book on seed saving, Seed to Seed.