First of all, it's important to distinguish between the factory method pattern and the abstract factory pattern, for this see Differences between Abstract Factory Pattern and Factory Method and Why there are two separate patterns:Abstract Factory and Factory Method and What is the basic difference between the Factory and Abstract Factory Patterns?. As you can see, this is a bit tricky and therefore what I say in the following has to be taken with a grain of salt.
In particular, your OurClass
example occurs to me as a typical use case of the abstract factory pattern. More concretely, the abstract factory pattern gives you the flexibility to make the concrete type of objects being created a parameter of a class and a typical use case of it can be dependency injection (even though this is typically done in a more automated way), see also Dependency Injection vs Factory Pattern.
Roughly speaking, in the abstract factory pattern you delegate the construction of objects to an external class (and typically, this class is responsible for creating not only one but several related objects), whereas in the factory method pattern, you delegate the construction of objects to subclasses. You can also take the view that the abstract factory pattern uses the factory method pattern for its creation methods.
Thus, one simple answer to the question when to use the factory method pattern is the following: When the creation of objects is the subclass's responsibilty. This means, when only the subclass should or can decide what object needs to be created and thus is an aspect of the subclass's behavior and this brings us back full circle to your initial assumption and boils down to the question: When should I use inheritance?, respectively Prefer composition over inheritance?.
The abstract factory pattern on the other hand can be used in the case you describe it, when an external factor decides which objects need to be created and this flexibility is required, thus justifying the additional complexity needed for the code.