Mimicry is a survival strategy in which organisms deceive their predators by imitating other organisms or the surrounding environment. One example of this involves pupal color polymorphism, which is widely observed in butterflies and moths. It has been suggested that the pupal colors of Papilio butterflies are selected according to the tactile stimulation experienced before pupation (P). Specifically, larvae crawling on smooth leaves become green pupae, but those crawling on rough stems become brown pupae. These protective colors fit with the surrounding environment. However, the detailed molecular mechanisms underlying pupal polymorphism have generally remained unknown. To reveal these mechanisms, we first established control over the green and brown pupal coloration in Papilio polytes under laboratory conditions and clarified temporal and spatial changes of pupal pigments under both conditions. We also analyzed the expression of coloration genes during the pre-pupal stage and at P in the epidermis under the green and brown conditions, by RNA sequencing and quantitative RT-PCR. These analyses revealed that the brown pupal color is regulated mainly by melanin synthesis genes, tyrosine hydroxylase (TH) and laccase 2. In contrast, the green pupal color was suggested to be formed mainly through the expression of both multiple bilin binding protein (BBP)-related genes responsible for blue pigmentation and multiple juvenile hormone binding protein (JHBP)-related genes responsible for yellow pigmentation. Electroporation-mediated RNAi showed that the knockdown of TH or laccase 2 blocked the brown pupal coloration, and that the knockdown of BBP-or JHBP-related genes caused yellow or blue coloration in the green-conditioned pupae, respectively, supporting the above hypothesis. We here report how genes involved in the pupal coloration of P. polytes are regulated, which sheds light on the evolutionary process of pupal protective colors among Lepidoptera.