Here some additional information that may help better understand some of the other technically correct, but shorter answers.
In the strictest sense a Class Factory is a function or method that creates or selects a class and returns it, based on some condition determined from input parameters or global context. This is required when the type of object needed can't be determined until runtime. Implementation can be done directly when classes are themselves objects in the language being used, such as Python.
Since the primary use of any class is to create instances of itself, in languages such as C++ where classes are not objects that can be passed around and manipulated, a similar combined-effect can often be achieved by simulating "virtual constructors", where you call a base-class constructor but get back an instance of some derived class. This needs to be simulated because constructors cannot really be virtual in C++, which is why such object (not class) factories are usually implemented as standalone functions or static methods.
The best implementations are those that handle new candidate classes automatically when they are added rather than having only a certain finite set currently hardcoded into the factory (although the trade-off is often acceptable if the factory is the only place requiring modification).
James Coplien's 1992 book Advanced C++: Programming Styles and Idioms has details on one way to implement such virtual generic constructors in C++. There are even better ways to do this using C++ templates, but that was not covered in the book which predates their being added to the standard language definition. In fact, C++ templates themselves are class factories since they instantiate a new class whenever they're used with different actual type argument(s).
See also the related answers for the question "Class factory in Python" here.