Return course order with class prerequisites
As pointed out in a comment, the problem you are trying to solve is an instance of the more general problem of finding a topological sorting of a particular set.
In your case, the ordering is given by the "being a prerequisite of" relation.
At the implementational level, switching your dictionary with an adjacency matrix may improve the runtime.