People sometimes display moral flexibility by deciding that a commonly accepted moral norm ought not to apply in particular circumstances. But how? We explore this question in the context of queuing. We show that people's judgements about the moral permissibility of queue-cutting can be explained through cognitive processes related to moral contractualism: universalization, virtual bargaining, and functional thinking. Participants were presented vignettes depicting prospective queue-cutters, and asked whether it was morally permissible to queue-cut in those circumstances. We model these judgements with reference to the existence of a game-theoretic equilibrium supporting queue cutting in a repeated game, and to considerations of whether queue cutting would subvert or enact the function of a queue: if you pay the waiting cost, you should get the reward. These results support the notion that moral flexibility is in part related to contractualist moral principles.