How do you clone a graph when it may contain cycles?
Keep a map from each original node to its copy. Before you copy a node's neighbours, you register the copy of that node in the map. Then, whenever you reach a neighbour, you look it up in the map: if it has already been copied you reuse the existing copy, and if not you create it and copy it too.
The map is what makes the cloning terminate. In a graph with a cycle, a naive recursive clone would revisit the same nodes forever, because there is no point at which the recursion bottoms out. With the map, the second time you meet a node you find its copy already exists and you just link to it.
The mechanism is that the map both records what has been done and provides the identity of the copies. The copy of a node is created before its neighbours are processed, so a cycle back to that node finds the copy already registered and links to it rather than creating a second copy.
The trade-off to name is that the map needs one entry per node, so the space is linear in the size of the graph, and the lookup is a hash operation so the time is also linear. The deeper point is the ordering requirement: creating the copy before recursing is what breaks the cycle, and reversing those two steps reintroduces the infinite recursion. A related detail is that the clone must preserve the graph's structure exactly, including the direction of edges and whether edges are directed or undirected.