The word caste in English translates two related Indian concepts: varna and jati. The varnas are four categories, in theory defined by occupation. From the most to least ritually pure these occupations are:
Priests
Warriors/nobles
Merchants/craftsmen
Laborers/servants
Someone outside this system is 'avarna': casteless, outcaste, an untouchable, etc. The second concept is jati. There are numerous jatis which vary by region, they are generally more specific than the varnas and correspond to jobs, such as blacksmithing. Like the varnas, jatis are defined by birth, and have different levels of ritual purity associated with them. They overlap with the varnas in a complex way, and it's not always clear what the relationship between the two is. Due to this birth-defined purity, an impure job has an associated impure jati.
That's the theoretical framework, but why untouchable status appeared is another issue. The most common explanation is that it separated higher jatis from ritual impurities. The above example of a blacksmith was considered very impure, and blacksmith families were untouchables. This may be due to bellows being made of cow leather, as cows are considered sacred and anything involving their slaughter is very ritually polluting. Another example is those who work in cremation grounds, as dead bodies are considered highly polluting. Ritual pollution could be passed on by contact, or even by viewing a source of pollution. Thus proximity with polluted people was avoided by those of purer jatis, especially priests who had to maintain purity to carry out religious rites. It's unclear exactly how this stratification first arose, but the purity of the priests is a development of their role in vedic rituals dating to before 1000 BC, the theory of purity evolved to encompass all of society, and priestly writings described an ideal stratification, with themselves at the top. Thus, untouchables tended to live on the fringes of settlements to avoid polluting the priests and other high castes, whose purity was believed to allow communion with the Gods and to preserve universal order.
It's difficult to say what it was like to be a pre-modern untouchable, as they were oppressed classes barred from formal education, so their views aren't available to us. There were campaigners against the caste system who didn't recognise untouchability. These were mainly the Buddhists and Jains, but also some Hindu reformers like Basavanna in the 12th century AD, who encouraged marriage betweens different jatis. In priest-dominated society, untouchables were socially excluded and relegated to unpleasant work such as moving dead bodies and cleaning waste, so it's likely that life was quite destitute for most untouchables, although we're talking about a large geographic area and a huge expanse of time. Despite the ostracism, untouchables were still a part of society as their menial jobs were necessary, and they had a limited place in Hindu rituals which took their low status into account. One example of a traditional ritual involving untouchables was observed by Alf Hilterbeital in 1984, in which the meat from a buffalo sacrifice was offered to the village untouchables to eat. However, this wasn't simple generosity, as meat-eating is considered polluting, and the ritual also involved an offering of meat to demons, the only beings lower than untouchables in purity.
Under British rule it was possible for untouchables to travel to Indian cities or abroad for non-traditional occupations and even to gain access to education. One such foreign-educated untouchable was Bhimrao Ramji Ambedkar who became a leading campaigner for untouchable rights and was involved in the Indian independence movement. For him, untouchable status was that of total ostracism, and he entirely rejected the concept, wishing to reform Hinduism to remove it. Eventually he considered Hinduism impossible to reform and converted to Buddhism. So for Bhimrao, untouchable status was clearly extremely negative and was an aberration to be done away with.
Soon after independence, the Indian government removed any legal recognition of untouchable status and made caste discrimination illegal. However, discrimination still continued and some provisions for untouchables were contentious with high-caste hindus, for example reserved places in higher education and certain jobs, similar to the American practice of 'affirmative action'.
I've used English words as much as possible to make the post accessible. Here are the technical words they correspond to.
Untouchable = various; modern terms include 'dalit' (oppressed) and 'harijan' (child of God)
Laborer/servant = śūdra
Merchant/craftsman = vaiśya
Warrior/noble = kṣatriya
Priest = brāhmaṇa (anglicised as 'brahmin')
Ritually pure = śuddha
Ritually impure = aśuddha
Sources
Flood, G. (1996) An Introduction to Hinduism. Cambridge: Cambridge University Press, pp 59-61, 216-219
Johnson, W.J. (2009) Oxford Dictionary of Hinduism. Oxford: Oxford University Press, entries: 'Basava, Brāhmaṇa, Harijans, Jati, Untouchables, Varna'
Keay, J. (2010) India: A History (2nd edn). London: HarperPress, pp 33-34, 54
Kinsley, D.R. (1993) Hinduism: A Cultural Perspective (2nd edn). Englewood Cliffs, NJ: Prentice-Hall, pp 18, 152-157
Stein, B. (1998) A History of India. Oxford: Blackwell Publishers Ltd., pp 330-334
Let me first address the first part of your question. How did the untouchables come to exist as a caste
The best place to start would be the Mauryan period as we have a complete record of the Mauryan codex via the Arthashastra.
First, we must understand that caste is not, was not an all encompassing monolith that it became during the British Raj. It was (and still is) broken up into,
Now, during the Mauryan period and till about the 1600 when the Castes started to stratify and which then accelerated under the Raj, your Jaati was given to you at birth but your Varna determined your status.
For instance, the Nanda emperors were descendant from a servant woman, a concubine in the harem. Their ostensibly lowly Jaati didn't preclude them from taking power and declaring themselves a Kshatriya Varna. Shivaji Maharaja was another classic case. Born in a family of cowherds (thus a very low caste), when he took power he simply had himself declared a Kshatriya and his caste a Kshatriya caste.
In other words Varna was mobile and your Jaati didn't preclude this mobility.
Getting back to the Mauryan codex, it says that you had 4 main varnas (priests, warriors, traders, farmers) you had sub varnas but let us not get side tracked. The law protected all these varnas. You had all manner of rights (property, inheritance, marriage, education etc) to these varnas. These groups were called the Aryaputra (sons of aryans would be a loose translation)
You then had the antavayasin (forest dwellers) and this is what interests us in the context of your question.
These were the literal outcasts. They were deemed non aryans, stripped of all rights due to Aryaputra (even lepers and demented people had rights, like right to shelter and food, not this group though. They had zero).
This group was divided into,
Chandalas - these were traditionally the cremation ground workers. This was a "hereditary" Varna, the son of a chandala could only be a chandala. This group was similar to the Japanese Burakumin class. Even this group had some rights.
Patita (the fallen). This group previously belonged to a Varna, however various transgressions mandated being exiled and idk for lack of a better word, "decasted"? And those stripped of their caste became the patita.
They were the lowest of the low and it is from this group on that punishments existed even for touching a Aryaputra. They were to strictly remain outside cities and villages and never to even touch a pure born. Mind you though, his family was still considered pure born. So let's say you are a Vaishya varna (trader) convicted of murdering a Brahmin. You would be stripped of your vaishya heritage and considered a Patita. Your children and wife though would remain Vaishya. In fact your wife was now free to remarry. Your parents remained Vaishya but your were prevented from inheriting their wealth.
Svapakas - Dog breeders, they were also banished from the cities and villages and this group was on par with the chandala and again prevented from even touching a pure born. It worked both ways. An Aryan man having Congress (as the Arthashastra puts it) with a Svapaka (or Chandala) woman would be exiled and become a Patita. In reverse though the Svapaka or Chandala man was put to death.
This is where the seeds of the untouchable system was born. Keep in mind though, Slavery was banned in the empire and even bonded /indentured labourers had rights and protections that were denied to the Svapaka, Chandala and Patita.
As these were hereditary (except in the case of the patita as they simply would have died out after a generation), Chandala and Svapaka continued to remain outside the pale. Thus were born the first of the untouchables in India.
Sources -
Arthashastra by Kautilya
Beyond the 4 varnas by Prabhati Mukerjee,
The pariah problem by Rupa Vishwanath.
Nicholas Dirk's Castes of Mind for the Raj era changes to the caste system