The answer is simple. What distinguishes a fruit from a vegetable isn't whether it is sweet or not. It has to do with which part of the plant we eat.
Botanically speaking, a fruit is the fleshy part of the plant that surrounds a seed or seeds. So apples, peaches, plums, grapes, pears and bananas, which we commonly call "fruits," indeed are. And so are tomatoes, peppers, cucumbers and squashes.
A vegetable's edible parts are its leaves, stems or roots. So lettuce and spinach are vegetables, because we eat the leaves. Asparagus is a vegetable - we eat the stems. And "root crops" like beets, carrots, potatoes and onions are also in the vegetable category.