Your intuition is correct, there is a subtle difference. I'll use a watermelon as an example.
XがYの形をしている
For「XがYの形をしている」it means that X has the shape of Y "voluntarily" in a sense. Your example vegetable naturally grows in the shape of a cucumber, so you can use「する」to state something about its shape. The same goes for my watermelon:
スイカは球{たま}の形をしています。(More commonly: スイカは丸{まる}いです。)
Watermelons are shaped like spheres. (Watermelons are round.)
The「形をしている/います」indicates that watermelons naturally grow into spheres. Among other things, you use「形をしている」to describe for example the shape of clouds, of landscapes or even weirdly shaped vegetables due to natural mutations.
XがYの形になる
For「XがYの形になる」it means that something "involuntary" happens to the shape, or that someone or something has somehow manipulated it. Japan happens to grow watermelons and other fruits and vegetables in various shapes, which you can see for yourself on this website about growing cube-shaped watermelons for example. On that website you can read:
四角{しかく}いスイカは、実{み}が小{ちい}さいうちに四角い専用{せんよう}容器{ようき}に入{い}れることで、実が大{おお}きくなった時{とき}に容器の形になるようにされたものです。
Square watermelons are grown inside of special cubic containers while the fruit is still small, such that the fruit grows in the shape of the container.
This is a clear example of shape manipulation, as indicated by the「~形になる」at the end of the sentence.