All sorting in MongoDB is done in memory, the amount of memory used can vary. Ideally, queries should be constructed to use indexes to support sorting (see this page for more details).
That page describes what happens when an index cannot be used to support the sorting for the query.
If MongoDB cannot use an index or indexes to obtain the sort order, MongoDB must perform a blocking sort operation on the data. A blocking sort indicates that MongoDB must consume and process all input documents to the sort before returning results. Blocking sorts do not block concurrent operations on the collection or database.
In terms of the SORT_KEY_GENERATOR stage, that is where results are sorted in-memory in that stage. It’s equally true to say the SORT stage is done in memory. BOTH of the stages you highlighted indicated that in-memory sorting occurred.
Ideally, if you can construct an index where the results from the index are returned in the sorting order you desire then you will not have to perform any sorting as the index will have done this for you. This requires consideration for how best to design your queries and how to design your indexes to support both the queries and those queries that need to have their results returned in a particular sorted order.
Hope this makes sense and good luck with the course!