All people produce wastes (wee and poop). These wastes contain bacteria and other microbes which can cause disease if they get into drinking water (See Dr John Snow and cholera). The wastes also smell as they decompose.
The idea of a toilet/ latrine/ water closet/ lavatory/ comfort station/ bathroom/ rest room etc. is to get rid of human waste is a convenient way that does not give any public health problems.
Most human waste is removed by flushing it away using a strong current of water from a cistern. But this needs a supply of water and somewhere to flush it to. In countryside areas, the waste goes to a cess pit, which is a large underground tank in which the waste is digested by bacteria. In cities it goes into the mains where it is taken to sewage works.
In poorer countries there may be no way of getting rid of waste except by using 'long drops', shafts dug into the ground. This doesn't use water at all.