Kata is a japanese word meaning form. It is a system of individual training incorporating highly practical combat techniques and notions. Practice of kata is an integral and essential part of karate along with kihon and kumite. Kata might look like some dance moves to non-karatekas but in fact it is a combination of stance, punches, blocks, kicks, footwork that forms an imaginary combat. When you breakdown a kata, you will see that it consists of defense and counter attacks. You will have to imagine that one is actually fighting one or more opponents as the kata is executed. This visualization transforms the kata from a series of movements into a meaningful and realistic aid during a fight. Karate was developed when there was an invasion and the weapons were banned. These events lead to upsurge in karate training.
An imaginary combat when practiced again and again will make you prepared for a real combat. It is not possible that the kata practiced will be similar to the real fight. The attacker will attack in a random manner which will not be the same as you expect when practicing kata. You will have to apply the movements accordingly as you face the attacker or attackers. Kata not only helps in a defence and counter strike but also helps develop strength, stamina, and speed. Kata is succeeded by Bunkai which is the breakdown of kata practically. It is more like a demonstration. In conclusion, the purpose of kata is to prepare you for effective combat. Here is a quote about kata from ancient master Gichin Funakoshi who is the founder of shotokan style of karate:
Sparring does not exist apart from the kata but for the practice of the kata.
–Gichin Funakoshi, Founder of Shotokan