Cucumbers are actually related to melons and watermelons! Bean pods and many kinds of nuts are counted as fruits too.
It can be difficult to know when something is a fruit or a vegetable. Scientists and cooks use different definitions of "fruit". Scientifically, fruits have seeds and develop from the ovary in the base of a flower. We use "vegetable" to describe the other edible parts of a plant (leaves, roots, etc.).
Tomatoes and cucumbers serve as vegetables in cooking because they're not sweet like most fruits.
(Sources: 1, 2, 3)