People have to understand that the process of evolution is not conscious, and it doesn’t work to improve and better a species, to guide it up the ladder towards a more ‘perfect’ form of life. Evolution (at least the core natural selection) works on populations rather than through individuals. We lost the tail (or rather it drastically shortened) because it would have been an unnecessary ‘caudate’ demanding energy and material resources through various cellular systems. Those with shorter tails, and eventually very short tails would have an advantage, no matter how small. The cost of losing the tale in the process is less than keeping it. The coding for the tail however isn’t lost, the pseudo-genes I expect (I haven’t checked) have merely lost either their protein coding ability or have been chemically ‘switched off’.
This is why ‘Atavisms’ still appear. In short, children are still sometimes born with a tail. Often the tail lacks muscle structure, but sometimes there is very limited muscle use. The coding has been accidentally re-expressed a little.
We share a common ancestor most recently with Chimpanzees and Bonobos (around 6 million years ago) and before that Gorillas, and a little further still Orangutans. It is no accident we all lack a useful caudate/tail. We can determine then that our tails became genetically defunct at least through our common ancestor if not before.
Genetic tinkering yet again. The tail cannot form fully, but retains its inherited past. In many ways the development of the foetus mirrors our evolutionary history, albeit in the early stages of life through the developmental foetus .
Early embryos of various species display some ancestral feature, like the tail on this human foetus. These features normally disappear in later development, but it may not happen if the animal has an atavism.
The tail is of course present in the embryonic stages. Also in the same way the buds for the rear limbs (legs) of the Whales/Dolphin are present but reabsorbed in the foetus stage.
For a long time, it was assumed that the loss of the tail was something that occurred as hominoidea (the apes) developed an orthograde posture (the manner of upright walking in which the upper limbs swing in opposition to one another). Presumably, the improved balance allowed animals to walk upright for further and longer and the muscles of what was once the tail adapted to a different role, i.e. supporting the weight of the body above.
However, that hypothesis was turned on its head as it became increasingly apparent that species of an ancient genus of primate known as Proconsul lacked tails. Proconsul’s actual taxonomic status is very controversial since it has a mixture of traits (like taillessness) that are indicative of modern apes and others that are not. Many have classified it as an early hominoidea genus, but others have argued that its origins lie prior to this, before the split of old world monkeys and apes. Either way, it shows that tails were lost before the evolution of orthograde posture.
It is now believed that the loss of the tail in apes was coterminous with the evolution of stronger grips, enhanced joint mobility and limb bone elongation that allowed for slower but more precise arboreal movement. Under such circumstances, the balance offered by a tail likely became less and less necessary. An additional consequence of this grasping arboreal movement was that animals could become larger, a situation in which tails could actually become a hindrance.