Video games were not invented for one grand purpose — they emerged from research, curiosity and a bit of play.
Early experiments in the 1950s and 60s came out of university and laboratory settings, where engineers with access to enormous mainframes used them to demonstrate what the machines could do. Building a playable demonstration was a way of showing off computing power, testing interactive input and, frankly, having fun on expensive equipment.
Commercial games followed once the hardware got cheaper, and their purpose became straightforward: entertainment. Later, people found plenty of other uses — education, training simulations, therapy, exercise and social connection among them.
So the short answer is that games began as technical curiosity and became a medium for play.