The tomato is botanically a fruit because it contains the ovary and the seeds of a flowering plant. Because it is all contained within the tomato and the outside structure keeps the seeds protected, it is a fruit even though it is used as a vegetable.
Eggplants, cucumbers and squashes are also fruits that are used as vegetables. Because of the complications, there have been legal disputes about it in the past. In 1887, the U.S. imposed taxes on vegetables but not fruits, and in 1983, the U.S. Supreme Court declared that the tomato is a vegetable rather than a fruit because they are generally served with dinner rather than desert.