How could we(or any other organism) have developed ears through evolution when before having ears we did not know that sound waves existed or there was anything such as hearing? How did the first hearing organ develop? The same can be asked for the other sense organs as well.
When you are asking about the evolution of organs, you are already five steps ahead of yourself. To have sensory organs, you need cells that react to some stimulus:
- Hearing, Touch: Mechanical stimulus
- Smell, some pain: Chemical stimulus
- Sight: Optic stimulus
- Other (non-human) organisms can also sense electric fields, magnetic fields, ...
As soon as you have those, having 'organs' that house a lot of those cells surrounded by tissues that aid in the reception of these stimuli, is relatively trivial.
But isn't a sensory cell totally complicated? It is. But: A simple neuron already is a sensory cell of sorts: It reacts to electrical and chemical imbalances.
But isn't then a neuron totally comlicated? It is. But: A simple non-neuronal cell already has a lot of the intricate machinery that a neuron does - a neuron mostly has some special parts and structures that make it a neuron. A simple cell also does react to chemical and other stimuli (this is why hormones work, and how little one-celled animals can orient themselves towards the light or food, or away from dangerous chemicals)
But isn't a run-of-the-mill cell totally complicated? It is. But it actually is just the workings of several archaic cells crammed into one (one of the more popular theories on Eukaryote evolution has them result from a very intense partnership of several more basic cells). And those archaic cells can also react to stimuli (they manage their metabolism according to the available food, for instance)
But isn't a basic cell totally complicated? It is. But is actually is just the interaction of several molecules that have some very interesting properties - DNA/RNA can function as an information storage, but are at the same time tools that can cowork with other DNA/RNA, and also interfaces/interferes with proteins in interesting ways.
But aren't big molecules totally complicated? They are. We still need supercomputers to reliably model all of the intricacies of any given Protein-Protein or Protein-RNA interaction. Many proteins behave differently in different environments (electromagnetic field strengths, chemical environment, temperature and mechanical factors (e.g. ultrasound)) - they could be said to 'react' to certain triggers. But they are actually just chains of repetitive elements (so called polymers of so called monomers).
But aren't those monomers totally complicated? Some are, but here we slowly get into the realm of 'mostly modellable on a hefty home computer'.
So we have systems of systems of systems... All of them very complicated.
But evolution is not a process that involves understanding ot planning. It is simply the result of coincidences and inheritance. You can see colors that many animals cannnot. You have the requisite molecules in your sensory cells in your eyes. Some people can see more colors than you, an inheritable trait. Some people can see less colors. Currently those people have no evolutionary profit from this - they reproduce and die with the same probability as the rest of us. Likewise there are a million (possibly billion?) such traits in every human. Traits that are different from the rest. Little things. Ineffective things (= having no net effect). But there might come a time where seeing one color or not seeing it (= not being distracted by it) will give a continuous net positive or net negative effect on the reproduction of those people carrying that trait. That is the time when that trait will start to be present in a larger piece of the population (over many generations). The people carrying that trait will also be different from one another. And the ones carrying the traits with the most positive net effect will multiply the most, etc. Humans in some distant future then can eye-sense some X-factor we cannot even describe currently (try describing different colors to a blind person) and thus have, say, Xeyes.
Organism don't have any intention to evolve a certain. As soon as a mutation creates a protein that can change conformation in response to a given sound frequency, then the organism carrying this information has opportunity for making use of this new signal. If this new mutation is beneficial, then it can be selected for and will increase in frequency in the population.