SetNode does not work, it always starts node after the one you set. Below is the correct code
Transition leavingTransition = new Transition(DYNAMIC_TRANSITION);
leavingTransition.setTo(executionContext.getProcessDefinition().getNode("Nodename"));
leavingTransition.setFrom(executionContext.getNode());
executionContext.leaveNode(leavingTransition);