Early computers were so expensive that it was unthinkable that you would have an entire computer to yourself. Instead, many people would use a single “timesharing” computer system. Unfortunately, early primitive operating systems lacked technologies like memory protection. If a program accidentally malfunctioned, it would sometimes end up crashing other programs, or the operating system itself.
Computer scientists tend to have a strange sense of humor, and some of them decided to make competitive program-crashing into a sport. Rather than crashing the actual computer, they built software that modeled a much simpler virtual computer, designed so it could run malicious programs without damaging the real operating system–much like the Java virtual machine in many web browsers.